List of all members.
Detailed Description
This class provides an Iterator interface to a BufferedReader. This covers the most common use-cases for reading from files without ugly code to check whether we got a line or not.
- Author:
- wren ng thornton wren@.nosp@m.user.nosp@m.s.sou.nosp@m.rcef.nosp@m.orge..nosp@m.net
-
Matt Post post@.nosp@m.cs.j.nosp@m.hu.ed.nosp@m.u
Constructor & Destructor Documentation
Opens a file for iterating line by line. The special "-" filename can be used to specify STDIN. GZIP'd files are tested for automatically.
- Parameters:
-
filename | the file to be opened ("-" for STDIN) |
Wraps an InputStream for iterating line by line. Stream encoding is assumed to be UTF-8.
Member Function Documentation
This method will close the file handle, and will raise any exceptions that occured during iteration. The method is idempotent, and all calls after the first are no-ops (unless the thread was interrupted or killed). For correctness, you must call this method before the object falls out of scope.
Iterates over all lines, ignoring their contents, and returns the count of lines. If some lines have already been read, this will return the count of remaining lines. Because no lines will remain after calling this method, we implicitly call close.
- Returns:
- the number of lines read
We attempt to avoid leaking file descriptors if you fail to call close before the object falls out of scope. However, the language spec makes no guarantees about timeliness of garbage collection. It is a bug to rely on this method to release the resources. Also, the garbage collector will discard any exceptions that have queued up, without notifying the application in any way.
Having a finalizer means the JVM can't do "fast allocation" of LineReader objects (or subclasses). This isn't too important due to disk latency, but may be worth noting.
- See also:
- Performance Tips
-
Techniques
Returns true
if the iteration has more elements. (In other words, returns true
if next
would return an element rather than throwing an exception.)
Return self as an iterator.
Return the next line of the file. If an error is encountered, NoSuchElementException is thrown. The actual IOException encountered will be thrown later, when the LineReader is closed. Also if there is no line to be read then NoSuchElementException is thrown.
Chain to the underlying ProgressInputStream.
- Returns:
- an integer from 0..100, indicating how much of the file has been read.
This method is like next() except that it throws the IOException directly. If there are no lines to be read then null is returned.
Determine if the reader is ready to read a line.
Member Data Documentation