it.unimi.dsi.sux4j.io
Class FileLinesList
java.lang.Object
it.unimi.dsi.fastutil.objects.AbstractObjectCollection<K>
it.unimi.dsi.fastutil.objects.AbstractObjectList<MutableString>
it.unimi.dsi.sux4j.io.FileLinesList
- All Implemented Interfaces:
- ObjectCollection<MutableString>, ObjectIterable<MutableString>, ObjectList<MutableString>, Stack<MutableString>, java.lang.Comparable<java.util.List<? extends MutableString>>, java.lang.Iterable<MutableString>, java.util.Collection<MutableString>, java.util.List<MutableString>, java.util.RandomAccess
public class FileLinesList
- extends AbstractObjectList<MutableString>
- implements java.util.RandomAccess
A wrapper exhibiting the lines of a file as a list.
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.
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 l bits, where l is the average line length.
- Since:
- 1.1
- Author:
- Sebastiano Vigna
Constructor Summary |
FileLinesList(java.lang.CharSequence filename,
java.lang.String encoding)
Creates a file-lines collection for the specified filename with the specified encoding, default buffer size and with all terminators. |
FileLinesList(java.lang.CharSequence filename,
java.lang.String encoding,
int bufferSize)
Creates a file-lines collection for the specified filename with the specified encoding, buffer size and with all terminators. |
FileLinesList(java.lang.CharSequence filename,
java.lang.String encoding,
int bufferSize,
java.util.EnumSet<FastBufferedInputStream.LineTerminator> terminators)
Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set. |
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectList |
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, top |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
clear, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
Methods inherited from interface it.unimi.dsi.fastutil.Stack |
isEmpty |
FileLinesList
public FileLinesList(java.lang.CharSequence filename,
java.lang.String encoding,
int bufferSize,
java.util.EnumSet<FastBufferedInputStream.LineTerminator> terminators)
throws java.io.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 for FastBufferedInputStream
.terminators
- a set of line terminators.
- Throws:
java.io.IOException
FileLinesList
public FileLinesList(java.lang.CharSequence filename,
java.lang.String encoding,
int bufferSize)
throws java.io.IOException
- 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 for FastBufferedInputStream
.
- Throws:
java.io.IOException
FileLinesList
public FileLinesList(java.lang.CharSequence filename,
java.lang.String encoding)
throws java.io.IOException
- 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:
java.io.IOException
size
public int size()
- Specified by:
size
in interface java.util.Collection<MutableString>
- Specified by:
size
in interface java.util.List<MutableString>
get
public MutableString get(int index)
- Specified by:
get
in interface java.util.List<MutableString>
get
public MutableString get(int index,
FastBufferedInputStream fastBufferedInputStream,
java.nio.ByteBuffer byteBuffer,
java.nio.CharBuffer charBuffer,
java.nio.charset.CharsetDecoder decoder)
listIterator
public FileLinesList.FileLinesIterator listIterator(int index)
- Specified by:
listIterator
in interface ObjectList<MutableString>
- Specified by:
listIterator
in interface java.util.List<MutableString>
- Overrides:
listIterator
in class AbstractObjectList<MutableString>
toString
public java.lang.String toString()
- Overrides:
toString
in class AbstractObjectList<MutableString>