java.io
Class BufferedReader
- Closeable, Readable
This subclass of
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 8192 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
BufferedReader(Reader in) - Create a new
BufferedReader that will read from the
specified subordinate stream with a default buffer size of 8192 chars.
|
BufferedReader(Reader in, int size) - Create a new
BufferedReader that will read from the
specified subordinate stream with a buffer size that is specified by the
caller.
|
void | close() - This method closes the underlying stream and frees any associated
resources.
|
void | mark(int readLimit) - Mark a position in the input to which the stream can be
"reset" by calling the
reset() method.
|
boolean | markSupported() - Returns
true to indicate that this class supports mark/reset
functionality.
|
int | read() - Reads an char from the input stream and returns it
as an int in the range of 0-65535.
|
int | read(char[] buf, int offset, int count) - This method read chars from a stream and stores them into a caller
supplied buffer.
|
String | readLine() - This method reads a single line of text from the input stream, returning
it as a
String .
|
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
mark() method
was called.
|
long | skip(long count) - This method skips the specified number of chars in the stream.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
BufferedReader
public BufferedReader(Reader in)
Create a new BufferedReader
that will read from the
specified subordinate stream with a default buffer size of 8192 chars.
in
- The subordinate stream to read from
BufferedReader
public BufferedReader(Reader in,
int size)
Create a new 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 use
mark
public void mark(int readLimit)
throws IOException
Mark a position in the input to which the stream can be
"reset" by calling the
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.
- mark in interface Reader
readLimit
- The number of chars that can be read before the mark
becomes invalid
read
public int read()
throws IOException
Reads an char from the input stream and returns it
as an int in the range of 0-65535. This method also will return -1 if
the end of the stream has been reached.
This method will block until the char can be read.
- read in interface Reader
- The char read or -1 if end of stream
read
public int read(char[] buf,
int offset,
int count)
throws IOException
This method read chars from a stream and stores them into a caller
supplied buffer. It starts storing the data at index
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 read
- The actual number of chars read, or -1 if end of stream.
readLine
public String readLine()
throws IOException
This method reads a single line of text from the input stream, returning
it as a 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
.
- The line of text read, or
null
if end of stream.
ready
public boolean ready()
throws IOException
This method determines whether or not a stream is ready to be read. If
this method returns false
then this stream could (but is
not guaranteed to) block on the next read attempt.
- ready in interface Reader
true
if this stream is ready to be read,
false
otherwise
reset
public void reset()
throws IOException
Reset the stream to the point where the
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.
- reset in interface Reader
skip
public long skip(long count)
throws IOException
This method skips the specified number of chars in the stream. It
returns the actual number of chars skipped, which may be less than the
requested amount.
This method first discards chars in the buffer, then calls the
skip
method on the underlying stream to skip the
remaining chars.
- skip in interface Reader
count
- The requested number of chars to skip
- The actual number of chars skipped.
BufferedReader.java
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.