public class FileLinesCollection extends AbstractCollection<MutableString>
Collection
.
Warning: the lines returned by iterators generated by
instances of this class are not cacheable. The returned value is
a MutableString
instance that is reused
at each call, and that is modified by a call to hasNext()
.
Thus, for instance,
ObjectIterators.unwrap( fileLinesColletion.iterator() );will not give the expected results. Use
allLines()
to get
the list of all lines (again, under the form of compact MutableString
s).
Note also that toString()
will return a single string containing all
file lines separated by the string associated to the system property line.separator.
An instance of this class allows to access the lines of a file as a
Collection
. Using direct access is strongly discouraged (it will require a full scan of the file), but
the iterator()
can be fruitfully used to scan the file, and 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 (FileLinesCollection.FileLinesIterator
)
is Closeable
, and should be closed after usage.
Using a suitable constructor, it is possible
to specify that the file is compresse in gzip format (in this case, it will be opened using a GZIPInputStream
).
Note that the first call to size()
will require a full file scan.
Modifier and Type | Class and Description |
---|---|
static class |
FileLinesCollection.FileLinesIterator
An iterator over the lines of a
FileLinesCollection . |
Constructor and Description |
---|
FileLinesCollection(CharSequence filename,
String encoding)
Creates a file-lines collection for the specified filename with the specified encoding.
|
FileLinesCollection(CharSequence filename,
String encoding,
boolean zipped)
Creates a file-lines collection for the specified filename with the specified encoding, optionally assuming
that the file is compressed using gzip format.
|
Modifier and Type | Method and Description |
---|---|
it.unimi.dsi.fastutil.objects.ObjectList<MutableString> |
allLines()
Returns all lines of the file wrapped by this file-lines collection.
|
FileLinesCollection.FileLinesIterator |
iterator() |
int |
size() |
String |
toString() |
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode
public FileLinesCollection(CharSequence filename, String encoding)
filename
- a filename.encoding
- an encoding.public FileLinesCollection(CharSequence filename, String encoding, boolean zipped)
filename
- a filename.encoding
- an encoding.zipped
- whether filename is zipped.public FileLinesCollection.FileLinesIterator iterator()
iterator
in interface Iterable<MutableString>
iterator
in interface Collection<MutableString>
iterator
in class AbstractCollection<MutableString>
public int size()
size
in interface Collection<MutableString>
size
in class AbstractCollection<MutableString>
public it.unimi.dsi.fastutil.objects.ObjectList<MutableString> allLines()
public String toString()
toString
in class AbstractCollection<MutableString>
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.