| |
|
| java.lang.Object java.io.InputStream java.io.FilterInputStream java.io.LineNumberInputStream
LineNumberInputStream | public class LineNumberInputStream extends FilterInputStream (Code) | | LineNumberInputStream is a filter class which counts the number of line
terminators from the data read from the target InputStream. A line delimiter
sequence is determined by '\r', '\n', or '\r\n'. When using read ,
the sequence is always translated into '\n'.
|
Method Summary | |
public int | available() Answers a int representing the number of bytes that are available before
this LineNumberInputStream will block. | public int | getLineNumber() Answers a int representing the current line number for this
LineNumberInputStream. | public void | mark(int readlimit) Set a Mark position in this LineNumberInputStream. | public int | read() Reads a single byte from this LineNumberInputStream and returns the
result as an int. | public int | read(byte[] buffer, int offset, int length) Reads at most length bytes from this LineNumberInputStream
and stores them in byte array buffer starting at
offset . | public void | reset() Reset this LineNumberInputStream to the last marked location. | public void | setLineNumber(int lineNumber) Sets the lineNumber of this LineNumberInputStream to the specified
lineNumber . | public long | skip(long count) Skips count number of bytes in this InputStream.
Subsequent read() 's will not return these bytes unless
reset() is used. |
LineNumberInputStream | public LineNumberInputStream(InputStream in)(Code) | | Constructs a new LineNumberInputStream on the InputStream in .
All reads are now filtered through this stream and line numbers will be
counted for all data read from this Stream.
Parameters: in - The non-null InputStream to count line numbers. |
available | public int available() throws IOException(Code) | | Answers a int representing the number of bytes that are available before
this LineNumberInputStream will block. This method returns the number of
bytes available in the target stream. Since the target input stream may
just be a sequence of \r\n characters and this filter only
returns \n then available can only
guarantee target.available()/2 characters.
int the number of bytes available before blocking. throws: IOException - If an error occurs in this stream. |
getLineNumber | public int getLineNumber()(Code) | | Answers a int representing the current line number for this
LineNumberInputStream.
int the current line number. |
mark | public void mark(int readlimit)(Code) | | Set a Mark position in this LineNumberInputStream. The parameter
readLimit indicates how many bytes can be read before a
mark is invalidated. Sending reset() will reposition the Stream back to
the marked position provided readLimit has not been
surpassed. The lineNumber count will also be reset to the last marked
lineNumber count.
This implementation sets a mark in the target stream.
Parameters: readlimit - The number of bytes to be able to read before invalidating themark. |
read | public int read() throws IOException(Code) | | Reads a single byte from this LineNumberInputStream and returns the
result as an int. The low-order byte is returned or -1 of the end of
stream was encountered. This implementation returns a byte from the
target stream. The line number count is incremented if a line terminator
is encountered. A line delimiter sequence is determined by '\r', '\n', or
'\r\n'. In this method, the sequence is always translated into '\n'.
int The byte read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
read | public int read(byte[] buffer, int offset, int length) throws IOException(Code) | | Reads at most length bytes from this LineNumberInputStream
and stores them in byte array buffer starting at
offset . Answer the number of bytes actually read or -1 if
no bytes were read and end of stream was encountered. This implementation
reads bytes from the target stream. The line number count is incremented
if a line terminator is encountered. A line delimiter sequence is
determined by '\r', '\n', or '\r\n'. In this method, the sequence is
always translated into '\n'.
Parameters: buffer - the non-null byte array in which to store the read bytes. Parameters: offset - the offset in buffer to store the read bytes. Parameters: length - the maximum number of bytes to store in buffer . The number of bytes actually read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. throws: NullPointerException - If buffer is null . throws: IllegalArgumentException - If offset or count are out ofbounds. |
reset | public void reset() throws IOException(Code) | | Reset this LineNumberInputStream to the last marked location. If the
readlimit has been passed or no mark has
been set, throw IOException. This implementation resets the target
stream. It also resets the line count to what is was when this Stream was
marked.
throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
setLineNumber | public void setLineNumber(int lineNumber)(Code) | | Sets the lineNumber of this LineNumberInputStream to the specified
lineNumber . Note that this may have side effects on the
line number associated with the last marked position.
Parameters: lineNumber - the new lineNumber value. |
skip | public long skip(long count) throws IOException(Code) | | Skips count number of bytes in this InputStream.
Subsequent read() 's will not return these bytes unless
reset() is used. This implementation skips
count number of bytes in the target stream and increments
the lineNumber count as bytes are skipped.
Parameters: count - the number of bytes to skip. the number of bytes actually skipped. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
|
|
|