Class FileLinesCollection
- java.lang.Object
-
- java.util.AbstractCollection<MutableString>
-
- it.unimi.dsi.big.io.FileLinesCollection
-
- All Implemented Interfaces:
Size64,Iterable<MutableString>,Collection<MutableString>
public class FileLinesCollection extends AbstractCollection<MutableString> implements Size64
A wrapper exhibiting the lines of a file as aCollection.Warning: the lines returned by iterators generated by instances of this class are not cacheable. The returned value is a
MutableStringinstance that is reused at each call, and that is modified by a call tohasNext(). Thus, for instance,ObjectIterators.unwrap(fileLinesColletion.iterator());will not give the expected results. UseallLines()to get the big list of all lines (again, under the form of compactMutableStrings). Note also thattoString()will return a single string containing all file lines separated by the string associated with the system propertyline.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 theiterator()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) isCloseable, and should be closed after usage.Using a suitable constructor, it is possible to specify that the file is compressed in
gzipformat (in this case, it will be opened using aGZIPInputStream).Note that the first call to
size64()will require a full file scan.- Since:
- 2.0
- Author:
- Sebastiano Vigna
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileLinesCollection.FileLinesIteratorAn iterator over the lines of aFileLinesCollection.
-
Constructor Summary
Constructors Constructor 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 usinggzipformat.
-
Method Summary
Modifier and Type Method Description ObjectBigList<MutableString>allLines()Returns all lines of the file wrapped by this file-lines collection.FileLinesCollection.FileLinesIteratoriterator()intsize()Deprecated.longsize64()Object[]toArray()Deprecated.<T> T[]toArray(T[] a)Deprecated.StringtoString()-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
FileLinesCollection
public FileLinesCollection(CharSequence filename, String encoding)
Creates a file-lines collection for the specified filename with the specified encoding.- Parameters:
filename- a filename.encoding- an encoding.
-
FileLinesCollection
public 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 usinggzipformat.- Parameters:
filename- a filename.encoding- an encoding.zipped- whetherfilenameis zipped.
-
-
Method Detail
-
iterator
public FileLinesCollection.FileLinesIterator iterator()
- Specified by:
iteratorin interfaceCollection<MutableString>- Specified by:
iteratorin interfaceIterable<MutableString>- Specified by:
iteratorin classAbstractCollection<MutableString>
-
size
@Deprecated public int size()
Deprecated.- Specified by:
sizein interfaceCollection<MutableString>- Specified by:
sizein interfaceSize64- Specified by:
sizein classAbstractCollection<MutableString>
-
allLines
public ObjectBigList<MutableString> allLines()
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 public Object[] toArray()
Deprecated.- Specified by:
toArrayin interfaceCollection<MutableString>- Overrides:
toArrayin classAbstractCollection<MutableString>
-
toArray
@Deprecated public <T> T[] toArray(T[] a)
Deprecated.- Specified by:
toArrayin interfaceCollection<MutableString>- Overrides:
toArrayin classAbstractCollection<MutableString>
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<MutableString>
-
-