public class FileLinesList extends AbstractObjectList<MutableString> implements RandomAccess, Serializable
An instance of this class allows to access the lines of a file as a
List. Contrarily to a FileLinesCollection, direct access
is possible and reasonably efficient, in particular when accessing nearby lines, and
all returned mutable strings are separate, independent instances.
Similarly to FileLinesCollection, instead, AbstractObjectList.iterator() can be
called any number of times, as it opens an independent input stream at each call. For the
same reason, the returned iterator type (FileLinesList.FileLinesIterator)
is Closeable, and should be closed after usage.
Note that toString() will return a single string containing all
file lines separated by the string associated to the system property line.separator.
Warning: this class is not synchronised. Separate iterators use separate input
streams, and can be accessed concurrently, but all calls to get(int) refer to the
same input stream.
Instances of this class perform a full scan of the specified file at construction time, representing the list of pointers to the start of each line using the Elias–Fano representation. The memory occupation per line is thus bounded by 2 + log ℓ bits, where ℓ is the average line length.
| Modifier and Type | Class and Description |
|---|---|
static class |
FileLinesList.FileLinesIterator
An iterator over the lines of a
FileLinesList. |
AbstractObjectList.ObjectSubList<K>| Constructor and Description |
|---|
FileLinesList(CharSequence filename,
String encoding)
Creates a file-lines collection for the specified filename with the specified encoding, default buffer size and with all terminators.
|
FileLinesList(CharSequence filename,
String encoding,
int bufferSize)
Creates a file-lines collection for the specified filename with the specified encoding, buffer size and with all terminators.
|
FileLinesList(CharSequence filename,
String encoding,
int bufferSize,
EnumSet<FastBufferedInputStream.LineTerminator> terminators)
Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set.
|
| Modifier and Type | Method and Description |
|---|---|
MutableString |
get(int index) |
MutableString |
get(int index,
FastBufferedInputStream fastBufferedInputStream,
ByteBuffer byteBuffer,
CharBuffer charBuffer,
CharsetDecoder decoder) |
FileLinesList.FileLinesIterator |
listIterator(int index) |
int |
size() |
String |
toString() |
add, add, addAll, addAll, addElements, addElements, compareTo, contains, ensureIndex, ensureRestrictedIndex, equals, getElements, hashCode, indexOf, iterator, lastIndexOf, listIterator, objectListIterator, objectListIterator, objectSubList, peek, pop, push, remove, removeElements, set, size, subList, topcontainsAll, isEmpty, objectIterator, removeAll, retainAll, toArray, toArrayclear, removeclone, finalize, getClass, notify, notifyAll, wait, wait, waitclear, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayobjectIterator, toArraypublic FileLinesList(CharSequence filename, String encoding, int bufferSize, EnumSet<FastBufferedInputStream.LineTerminator> terminators) throws IOException
filename - a filename.encoding - an encoding.bufferSize - the buffer size for FastBufferedInputStream.terminators - a set of line terminators.IOExceptionpublic FileLinesList(CharSequence filename, String encoding, int bufferSize) throws IOException
filename - a filename.encoding - an encoding.bufferSize - the buffer size for FastBufferedInputStream.IOExceptionpublic FileLinesList(CharSequence filename, String encoding) throws IOException
filename - a filename.encoding - an encoding.IOExceptionpublic int size()
size in interface Collection<MutableString>size in interface List<MutableString>size in class AbstractCollection<MutableString>public MutableString get(int index)
get in interface List<MutableString>public MutableString get(int index, FastBufferedInputStream fastBufferedInputStream, ByteBuffer byteBuffer, CharBuffer charBuffer, CharsetDecoder decoder)
public FileLinesList.FileLinesIterator listIterator(int index)
listIterator in interface ObjectList<MutableString>listIterator in interface List<MutableString>listIterator in class AbstractObjectList<MutableString>public String toString()
toString in class AbstractObjectList<MutableString>