Class FileLinesByteArrayIterable

All Implemented Interfaces:
Size64, Iterable<byte[]>

public class FileLinesByteArrayIterable extends Object implements Iterable<byte[]>, Size64
A wrapper exhibiting the lines of a file as an Iterable of byte arrays.

An instance of this class makes it possible to access the lines of a file as an Iterable of byte arrays. Reading is performed using FastBufferedInputStream.readLine(byte[], EnumSet), and follows the rules defined therein. No decoding is performed.

The result of a call to iterator() can be used to scan the file; each call will open an independent input stream. The returned iterator type (FileLinesIterator) is Closeable, and should be closed after usage. Exhausted iterators, however, will be closed automagically.

Using a suitable constructor it is possible to specify a decompression class, which must extend InputStream and provide a constructor accepting an InputStream (e.g., GZIPInputStream if the file is compressed in gzip format).

Convenience static methods makes it possible to build on the fly an iterator over an input stream using the same conventions.

This class implements size64(), which will return the number of lines of the file, computed with a full scan at the first invocation. However, it is also possible to specify at construction time the number of lines in the file to skip the first scan. It is responsibility of the caller that the specified size and the actual number of lines in the file do match.

Sebastiano Vigna