java.lang.Object | +--java.io.Reader | +--java.io.BufferedReader
BufferedReader(java.io.Reader in) Create a new |
BufferedReader(java.io.Reader in, int size) Create a new |
void | close() This method closes the stream |
void | mark(int readLimit) Mark a position in the input to which the stream can be
"reset" by calling the |
boolean | markSupported() Returns |
int | read(char[] buf, int offset, int count) This method read chars from a stream and stores them into a caller supplied buffer. |
int | read() |
java.lang.String | readLine() This method reads a single line of text from the input stream, returning
it as a |
boolean | ready() This method determines whether or not a stream is ready to be read. |
void | reset() Reset the stream to the point where the |
long | skip(long count) This method skips the specified number of chars in the stream. |
public BufferedReader(java.io.Reader in)
BufferedReader
that will read from the
specified subordinate stream with a default buffer size of 4096 chars.
in
- The subordinate stream to read frompublic BufferedReader(java.io.Reader in, int size)
BufferedReader
that will read from the
specified subordinate stream with a buffer size that is specified by the
caller.
in
- The subordinate stream to read fromsize
- The buffer size to usepublic void close()
IOException
- If an error occurspublic void mark(int readLimit)
reset()
method. The parameter
readlimit
is the number of chars that can be read from the
stream after setting the mark before the mark becomes invalid. For
example, if mark()
is called with a read limit of 10, then
when 11 chars of data are read from the stream before the
reset()
method is called, then the mark is invalid and the
stream object instance is not required to remember the mark.
Note that the number of chars that can be remembered by this method can be greater than the size of the internal read buffer. It is also not dependent on the subordinate stream supporting mark/reset functionality.
readLimit
- The number of chars that can be read before the mark
becomes invalidIOException
- If an error occurspublic boolean markSupported()
true
to indicate that this class supports mark/reset
functionality.
true
public int read()
public int read(char[] buf, int offset, int count)
offset
into
the buffer and attempts to read len
chars. This method can
return before reading the number of chars requested. The actual number
of chars read is returned as an int. A -1 is returned to indicate the
end of the stream.
This method will block until some data can be read.
buf
- The array into which the chars read should be storedoffset
- The offset into the array to start storing charscount
- The requested number of chars to readIOException
- If an error occurs.public String readLine()
String
. A line is terminated by "\n", a "\r", or
an "\r\n" sequence. The system dependent line separator is not used.
The line termination characters are not returned in the resulting
String
.
null
if end of stream.IOException
- If an error occurspublic boolean ready()
false
then this stream could (but is
not guaranteed to) block on the next read attempt.
true
if this stream is ready to be read, false
otherwiseIOException
- If an error occurspublic void reset()
mark()
method
was called. Any chars that were read after the mark point was set will
be re-read during subsequent reads.
This method will throw an IOException if the number of chars read from
the stream since the call to mark()
exceeds the mark limit
passed when establishing the mark.
IOException
- If an error occurs;public long skip(long count)
This method first discards chars in the buffer, then calls the
skip
method on the underlying stream to skip the remaining chars.
count
- The requested number of chars to skipIOException
- If an error occurs
FilterReader
buffers input from an underlying implementation to provide a possibly more efficient read mechanism. It maintains the buffer and buffer state in instance variables that are available to subclasses. The default buffer size of 512 chars can be overridden by the creator of the stream.This class also implements mark/reset functionality. It is capable of remembering any number of input chars, to the limits of system memory or the size of
Integer.MAX_VALUE