Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.io
Class BufferedReader  view BufferedReader download BufferedReader.java

java.lang.Object
  extended byjava.io.Reader
      extended byjava.io.BufferedReader
Direct Known Subclasses:
LineNumberReader

public class BufferedReader
extends Reader

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


Field Summary
(package private)  char[] buffer
           
(package private) static int DEFAULT_BUFFER_SIZE
           
(package private)  Reader in
           
(package private)  int limit
           
(package private)  int markPos
           
(package private)  int pos
           
private  java.lang.StringBuffer sbuf
          The line buffer for readLine.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
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.
 
Method Summary
private  void checkStatus()
           
 void close()
          This method closes the underlying stream and frees any associated resources.
private  int fill()
           
private  int lineEnd(int limit)
           
 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.
 java.lang.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.
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

Reader in

buffer

char[] buffer

pos

int pos

limit

int limit

markPos

int markPos

DEFAULT_BUFFER_SIZE

static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

sbuf

private java.lang.StringBuffer sbuf
The line buffer for readLine.

Constructor Detail

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.


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.

Method Detail

close

public void close()
           throws IOException
This method closes the underlying stream and frees any associated resources.

Specified by:
close in class Reader

markSupported

public boolean markSupported()
Returns true to indicate that this class supports mark/reset functionality.

Overrides:
markSupported in class Reader

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.

Overrides:
mark in class Reader

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.

Overrides:
reset in class Reader

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.

Overrides:
ready in class Reader

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.

Specified by:
read in class Reader

fill

private int fill()
          throws IOException

read

public int read()
         throws IOException
Description copied from class: Reader
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.

Overrides:
read in class Reader

lineEnd

private int lineEnd(int limit)

readLine

public java.lang.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.


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.

Overrides:
skip in class Reader

checkStatus

private void checkStatus()
                  throws IOException