Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » io » [javadoc | source]
java.io
abstract public class: Reader [javadoc | source]
java.lang.Object
   java.io.Reader

All Implemented Interfaces:
    Closeable, Readable

Direct Known Subclasses:
    FileReader, StringReader, LineNumberReader, PushbackReader, CharArrayReader, InputStreamReader, PipedReader, BufferedReader, ByteChannelReader, FilterReader, ConsoleReader

The base class for all readers. A reader is a means of reading data from a source in a character-wise manner. Some readers also support marking a position in the input and returning to this position later.

This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the #read(char[], int, int) and #close() methods needs to be overridden. Overriding some of the non-abstract methods is also often advised, since it might result in higher efficiency.

Many specialized readers for purposes like reading from a file already exist in this package.

Field Summary
protected  Object lock    The object used to synchronize access to the reader. 
Constructor:
 protected Reader() 
 protected Reader(Object lock) 
    Constructs a new {@code Reader} with {@code lock} used to synchronize critical sections.
    Parameters:
    lock - the {@code Object} used to synchronize critical sections.
    Throws:
    NullPointerException - if {@code lock} is {@code null}.
Method from java.io.Reader Summary:
close,   mark,   markSupported,   read,   read,   read,   read,   ready,   reset,   skip
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.Reader Detail:
 abstract public  void close() throws IOException
    Closes this reader. Implementations of this method should free any resources associated with the reader.
 public  void mark(int readLimit) throws IOException 
    Sets a mark position in this reader. The parameter {@code readLimit} indicates how many characters can be read before the mark is invalidated. Calling {@code reset()} will reposition the reader back to the marked position if {@code readLimit} has not been surpassed.

    This default implementation simply throws an {@code IOException}; subclasses must provide their own implementation.

 public boolean markSupported() 
    Indicates whether this reader supports the {@code mark()} and {@code reset()} methods. This default implementation returns {@code false}.
 public int read() throws IOException 
    Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached.
 public int read(char[] buf) throws IOException 
    Reads characters from this reader and stores them in the character array {@code buf} starting at offset 0. Returns the number of characters actually read or -1 if the end of the reader has been reached.
 public int read(CharBuffer target) throws IOException 
    Reads characters and puts them into the {@code target} character buffer.
 abstract public int read(char[] buf,
    int offset,
    int count) throws IOException
    Reads at most {@code count} characters from this reader and stores them at {@code offset} in the character array {@code buf}. Returns the number of characters actually read or -1 if the end of the reader has been reached.
 public boolean ready() throws IOException 
    Indicates whether this reader is ready to be read without blocking. Returns {@code true} if this reader will not block when {@code read} is called, {@code false} if unknown or blocking will occur. This default implementation always returns {@code false}.
 public  void reset() throws IOException 
    Resets this reader's position to the last {@code mark()} location. Invocations of {@code read()} and {@code skip()} will occur from this new location. If this reader has not been marked, the behavior of {@code reset()} is implementation specific. This default implementation throws an {@code IOException}.
 public long skip(long count) throws IOException 
    Skips {@code amount} characters in this reader. Subsequent calls of {@code read} methods will not return these characters unless {@code reset()} is used. This method may perform multiple reads to read {@code count} characters.