java.io
Class Reader

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.io.Reader
All Implemented Interfaces:
Closeable sample code for java.io.Closeable definition code for java.io.Closeable , Readable sample code for java.lang.Readable definition code for java.lang.Readable
Direct Known Subclasses:
BufferedReader sample code for java.io.BufferedReader definition code for java.io.BufferedReader , CharArrayReader sample code for java.io.CharArrayReader definition code for java.io.CharArrayReader , FilterReader sample code for java.io.FilterReader definition code for java.io.FilterReader , InputStreamReader sample code for java.io.InputStreamReader definition code for java.io.InputStreamReader , PipedReader sample code for java.io.PipedReader definition code for java.io.PipedReader , StringReader sample code for java.io.StringReader definition code for java.io.StringReader

public abstract class Reader
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Readable sample code for java.lang.Readable definition code for java.lang.Readable , Closeable sample code for java.io.Closeable definition code for java.io.Closeable

Abstract class for reading character streams. The only methods that a subclass must implement are read(char[], int, int) and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.

Since:
JDK1.1
See Also:
BufferedReader sample code for java.io.BufferedReader definition code for java.io.BufferedReader , LineNumberReader sample code for java.io.LineNumberReader definition code for java.io.LineNumberReader , CharArrayReader sample code for java.io.CharArrayReader definition code for java.io.CharArrayReader , InputStreamReader sample code for java.io.InputStreamReader definition code for java.io.InputStreamReader , FileReader sample code for java.io.FileReader definition code for java.io.FileReader , FilterReader sample code for java.io.FilterReader definition code for java.io.FilterReader , PushbackReader sample code for java.io.PushbackReader definition code for java.io.PushbackReader , PipedReader sample code for java.io.PipedReader definition code for java.io.PipedReader , StringReader sample code for java.io.StringReader definition code for java.io.StringReader , Writer sample code for java.io.Writer definition code for java.io.Writer

Field Summary
protected  Object sample code for java.lang.Object definition code for java.lang.Object lock sample code for java.io.Reader.lock definition code for java.io.Reader.lock
          The object used to synchronize operations on this stream.
 
Constructor Summary
protected Reader sample code for java.io.Reader.Reader() definition code for java.io.Reader.Reader() ()
          Create a new character-stream reader whose critical sections will synchronize on the reader itself.
protected Reader sample code for java.io.Reader.Reader(java.lang.Object) definition code for java.io.Reader.Reader(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  lock)
          Create a new character-stream reader whose critical sections will synchronize on the given object.
 
Method Summary
abstract  void close sample code for java.io.Reader.close() definition code for java.io.Reader.close() ()
          Close the stream.
 void mark sample code for java.io.Reader.mark(int) definition code for java.io.Reader.mark(int) (int readAheadLimit)
          Mark the present position in the stream.
 boolean markSupported sample code for java.io.Reader.markSupported() definition code for java.io.Reader.markSupported() ()
          Tell whether this stream supports the mark() operation.
 int read sample code for java.io.Reader.read() definition code for java.io.Reader.read() ()
          Read a single character.
 int read sample code for java.io.Reader.read(char[]) definition code for java.io.Reader.read(char[]) (char[] cbuf)
          Read characters into an array.
abstract  int read sample code for java.io.Reader.read(char[], int, int) definition code for java.io.Reader.read(char[], int, int) (char[] cbuf, int off, int len)
          Read characters into a portion of an array.
 int read sample code for java.io.Reader.read(java.nio.CharBuffer) definition code for java.io.Reader.read(java.nio.CharBuffer) (CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  target)
          Attempts to read characters into the specified character buffer.
 boolean ready sample code for java.io.Reader.ready() definition code for java.io.Reader.ready() ()
          Tell whether this stream is ready to be read.
 void reset sample code for java.io.Reader.reset() definition code for java.io.Reader.reset() ()
          Reset the stream.
 long skip sample code for java.io.Reader.skip(long) definition code for java.io.Reader.skip(long) (long n)
          Skip characters.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

lock sample code for java.io.Reader.lock

protected Object sample code for java.lang.Object definition code for java.lang.Object  lock
The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than this or a synchronized method.

Constructor Detail

Reader sample code for java.io.Reader() definition code for java.io.Reader()

protected Reader()
Create a new character-stream reader whose critical sections will synchronize on the reader itself.


Reader sample code for java.io.Reader(java.lang.Object) definition code for java.io.Reader(java.lang.Object)

protected Reader(Object sample code for java.lang.Object definition code for java.lang.Object  lock)
Create a new character-stream reader whose critical sections will synchronize on the given object.

Parameters:
lock - The Object to synchronize on.
Method Detail

read sample code for java.io.Reader.read(java.nio.CharBuffer) definition code for java.io.Reader.read(java.nio.CharBuffer)

public int read(CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  target)
         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed.

Specified by:
read sample code for java.lang.Readable.read(java.nio.CharBuffer) definition code for java.lang.Readable.read(java.nio.CharBuffer) in interface Readable sample code for java.lang.Readable definition code for java.lang.Readable
Parameters:
target - the buffer to read characters into
Returns:
The number of characters added to the buffer, or -1 if this source of characters is at its end
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if target is null
ReadOnlyBufferException - if target is a read only buffer

read sample code for java.io.Reader.read() definition code for java.io.Reader.read()

public int read()
         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Read a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs

read sample code for java.io.Reader.read(char[]) definition code for java.io.Reader.read(char[])

public int read(char[] cbuf)
         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

Parameters:
cbuf - Destination buffer
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs

read sample code for java.io.Reader.read(char[], int, int) definition code for java.io.Reader.read(char[], int, int)

public abstract int read(char[] cbuf,
                         int off,
                         int len)
                  throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Read characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

Parameters:
cbuf - Destination buffer
off - Offset at which to start storing characters
len - Maximum number of characters to read
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs

skip sample code for java.io.Reader.skip(long) definition code for java.io.Reader.skip(long)

public long skip(long n)
          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Skip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.

Parameters:
n - The number of characters to skip
Returns:
The number of characters actually skipped
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - If n is negative.
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs

ready sample code for java.io.Reader.ready() definition code for java.io.Reader.ready()

public boolean ready()
              throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Tell whether this stream is ready to be read.

Returns:
True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs

markSupported sample code for java.io.Reader.markSupported() definition code for java.io.Reader.markSupported()

public boolean markSupported()
Tell whether this stream supports the mark() operation. The default implementation always returns false. Subclasses should override this method.

Returns:
true if and only if this stream supports the mark operation.

mark sample code for java.io.Reader.mark(int) definition code for java.io.Reader.mark(int)

public void mark(int readAheadLimit)
          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.

Parameters:
readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If the stream does not support mark(), or if some other I/O error occurs

reset sample code for java.io.Reader.reset() definition code for java.io.Reader.reset()

public void reset()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Reset the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If the stream has not been marked, or if the mark has been invalidated, or if the stream does not support reset(), or if some other I/O error occurs

close sample code for java.io.Reader.close() definition code for java.io.Reader.close()

public abstract void close()
                    throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Close the stream. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.

Specified by:
close sample code for java.io.Closeable.close() definition code for java.io.Closeable.close() in interface Closeable sample code for java.io.Closeable definition code for java.io.Closeable
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs