Class FileLinesList
- All Implemented Interfaces:
it.unimi.dsi.fastutil.objects.ObjectCollection<it.unimi.dsi.lang.MutableString>, it.unimi.dsi.fastutil.objects.ObjectIterable<it.unimi.dsi.lang.MutableString>, it.unimi.dsi.fastutil.objects.ObjectList<it.unimi.dsi.lang.MutableString>, it.unimi.dsi.fastutil.Stack<it.unimi.dsi.lang.MutableString>, Serializable, Comparable<List<? extends it.unimi.dsi.lang.MutableString>>, Iterable<it.unimi.dsi.lang.MutableString>, Collection<it.unimi.dsi.lang.MutableString>, List<it.unimi.dsi.lang.MutableString>, RandomAccess, SequencedCollection<it.unimi.dsi.lang.MutableString>
An instance of this class allows to access the lines of a file as a List. Contrarily to a
FileLinesMutableStringIterable, direct access is possible and reasonably
efficient, in particular when accessing nearby lines, and all returned mutable strings are separate, independent instances.
Similarly to FileLinesMutableStringIterable, 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.
Implementation details
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.
- Since:
- 1.1
- Author:
- Sebastiano Vigna
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn iterator over the lines of aFileLinesList.Nested classes/interfaces inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectList
it.unimi.dsi.fastutil.objects.AbstractObjectList.ObjectRandomAccessSubList<K>, it.unimi.dsi.fastutil.objects.AbstractObjectList.ObjectSubList<K> -
Constructor Summary
ConstructorsConstructorDescriptionFileLinesList(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<it.unimi.dsi.fastutil.io.FastBufferedInputStream.LineTerminator> terminators) Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set. -
Method Summary
Modifier and TypeMethodDescriptionit.unimi.dsi.lang.MutableStringget(int index) it.unimi.dsi.lang.MutableStringget(int index, it.unimi.dsi.fastutil.io.FastBufferedInputStream fastBufferedInputStream, ByteBuffer byteBuffer, CharBuffer charBuffer, CharsetDecoder decoder) listIterator(int index) intsize()toString()Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectList
add, add, addAll, addAll, addElements, addElements, clear, compareTo, contains, ensureIndex, ensureRestrictedIndex, equals, forEach, getElements, hashCode, indexOf, iterator, lastIndexOf, listIterator, peek, pop, push, remove, removeElements, set, setElements, size, subList, toArray, toArray, topMethods inherited from class AbstractCollection
containsAll, isEmpty, remove, removeAll, retainAllMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversedMethods inherited from interface it.unimi.dsi.fastutil.objects.ObjectCollection
spliteratorMethods inherited from interface it.unimi.dsi.fastutil.objects.ObjectList
addAll, addAll, setElements, setElements, sort, spliterator, unstableSortMethods inherited from interface it.unimi.dsi.fastutil.Stack
isEmpty
-
Constructor Details
-
FileLinesList
public FileLinesList(CharSequence filename, String encoding, int bufferSize, EnumSet<it.unimi.dsi.fastutil.io.FastBufferedInputStream.LineTerminator> terminators) throws IOException Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set.- Parameters:
filename- a filename.encoding- an encoding.bufferSize- the buffer size forFastBufferedInputStream.terminators- a set of line terminators.- Throws:
IOException
-
FileLinesList
Creates a file-lines collection for the specified filename with the specified encoding, buffer size and with all terminators.- Parameters:
filename- a filename.encoding- an encoding.bufferSize- the buffer size forFastBufferedInputStream.- Throws:
IOException
-
FileLinesList
Creates a file-lines collection for the specified filename with the specified encoding, default buffer size and with all terminators.- Parameters:
filename- a filename.encoding- an encoding.- Throws:
IOException
-
-
Method Details
-
size
public int size()- Specified by:
sizein interfaceCollection<it.unimi.dsi.lang.MutableString>- Specified by:
sizein interfaceList<it.unimi.dsi.lang.MutableString>- Specified by:
sizein classAbstractCollection<it.unimi.dsi.lang.MutableString>
-
get
-
get
public it.unimi.dsi.lang.MutableString get(int index, it.unimi.dsi.fastutil.io.FastBufferedInputStream fastBufferedInputStream, ByteBuffer byteBuffer, CharBuffer charBuffer, CharsetDecoder decoder) -
listIterator
- Specified by:
listIteratorin interfaceList<it.unimi.dsi.lang.MutableString>- Specified by:
listIteratorin interfaceit.unimi.dsi.fastutil.objects.ObjectList<it.unimi.dsi.lang.MutableString>- Overrides:
listIteratorin classit.unimi.dsi.fastutil.objects.AbstractObjectList<it.unimi.dsi.lang.MutableString>
-
toString
- Overrides:
toStringin classit.unimi.dsi.fastutil.objects.AbstractObjectList<it.unimi.dsi.lang.MutableString>
-