Class FileLinesCollection
- All Implemented Interfaces:
Iterable<MutableString>, Collection<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 MutableStrings). Note also that
toString() will return a single string containing all file lines separated by the string
associated with 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 compressed 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.
- Since:
- 0.9.2
- Author:
- Sebastiano Vigna
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDeprecated.Please useFileLinesMutableStringIterable.iterator(java.io.InputStream, java.nio.charset.Charset, Class); thezippedoption of this class can be simulated by passing aGZIPInputStreamas decompressor. -
Constructor Summary
ConstructorsConstructorDescriptionFileLinesCollection(CharSequence filename, String encoding) Deprecated.Creates a file-lines collection for the specified filename with the specified encoding.FileLinesCollection(CharSequence filename, String encoding, boolean zipped) Deprecated.Creates a file-lines collection for the specified filename with the specified encoding, optionally assuming that the file is compressed usinggzipformat. -
Method Summary
Modifier and TypeMethodDescriptionit.unimi.dsi.fastutil.objects.ObjectList<MutableString> allLines()Deprecated.Returns all lines of the file wrapped by this file-lines collection.iterator()Deprecated.intsize()Deprecated.Object[]toArray()Deprecated.<T> T[]toArray(T[] a) Deprecated.toString()Deprecated.Methods inherited from class AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAllMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
FileLinesCollection
Deprecated.Creates a file-lines collection for the specified filename with the specified encoding.- Parameters:
filename- a filename.encoding- an encoding.
-
FileLinesCollection
Deprecated.Creates a file-lines collection for the specified filename with the specified encoding, optionally assuming that the file is compressed usinggzipformat.- Parameters:
filename- a filename.encoding- an encoding.zipped- whetherfilenameis zipped.
-
-
Method Details
-
iterator
Deprecated.- Specified by:
iteratorin interfaceCollection<MutableString>- Specified by:
iteratorin interfaceIterable<MutableString>- Specified by:
iteratorin classAbstractCollection<MutableString>
-
size
public int size()Deprecated.- Specified by:
sizein interfaceCollection<MutableString>- Specified by:
sizein classAbstractCollection<MutableString>
-
allLines
Deprecated.Returns all lines of the file wrapped by this file-lines collection.- Returns:
- all lines of the file wrapped by this file-lines collection.
-
toArray
Deprecated.- Specified by:
toArrayin interfaceCollection<MutableString>- Overrides:
toArrayin classAbstractCollection<MutableString>
-
toArray
public <T> T[] toArray(T[] a) Deprecated.- Specified by:
toArrayin interfaceCollection<MutableString>- Overrides:
toArrayin classAbstractCollection<MutableString>
-
toString
-
FileLinesMutableStringIterableinstead; thezippedoption of this class can be simulated by passing aGZIPInputStreamas decompressor.