Package blbutil
Class BlockLineReader
java.lang.Object
blbutil.BlockLineReader
Class BlockLineReader is a blbutil.FileIt that reads
blocks of lines from a file. The order of lines in the source file is
preserved by the returned string arrays. The hasNext() method
always returns true. After the final block of lines is returned
by the next() method, the next() method returns
BlockLineReader.SENTINAL on all subsequent invocations.
BlockLineReader.SENTINAL is guaranteed to be the only returned
array that has length 0.
Instances of class BlockLineReader are thread-safe.
Methods of this class will terminate the Java Virtual Machine with an error message if an I/O Exception is encountered.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the input stream and releases any system resources that are associated with it.static BlockLineReaderConstructs and returns a newBlockLineReaderfor the specified data.file()Returns the file from which the data are read, ornullif the data are read from standard input or if the data source is unknown.booleanhasNext()Returnstrue.String[]next()Returns the next element in the iteration.voidremove()Theremovemethod is not supported by this iterator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
SENTINAL
The string array returned bynext()after all blocks of lines have been read.
-
-
Method Details
-
create
Constructs and returns a newBlockLineReaderfor the specified data. Theclose()method of the returned object will invoke theclose()method on the specifiedFileIt<String>iterator. The calling thread should not directly invoke any methods of the specifiedFileIt<String>after it is passed to theBlockLineReader.create()method.- Parameters:
it- a file iterator that returns the lines of textblockSize- the maximum length a string array returned bynext()nBlocks- the maximum number of non-empty string arrays that will be buffered- Returns:
- a
BlockLineReaderfor the specified data. - Throws:
IllegalArgumentException- ifblockSize < 1 || nBlocks < 1NullPointerException- ifit == null
-
file
Description copied from interface:FileItReturns the file from which the data are read, ornullif the data are read from standard input or if the data source is unknown. -
close
public void close()Description copied from interface:FileItCloses the input stream and releases any system resources that are associated with it. If the input stream is already closed then invoking this method has no effect. -
hasNext
public boolean hasNext()Returnstrue. Thethis.next()method will returnBlockLineReader.SENTINALif the iterations has no more elements. -
next
Returns the next element in the iteration. ReturnsBlockLineReader.SENTINALif the iterations has no more elements. -
remove
public void remove()Theremovemethod is not supported by this iterator.- Specified by:
removein interfaceIterator<String[]>- Throws:
UnsupportedOperationException- if this method is invoked
-