Name

Reader

Synopsis

This abstract class is the superclass of all character input streams. It is an analog to InputStream, which is the superclass of all byte input streams. Reader defines the basic methods that all character output streams provide. read( ) returns a single character or an array (or subarray) of characters, blocking if necessary; it returns -1 if the end of the stream has been reached. ready( ) returns true if there are characters available for reading. If ready( ) returns true, the next call to read( ) is guaranteed not to block. close( ) closes the character input stream. skip( ) skips a specified number of characters in the input stream. If markSupported( ) returns true, mark( ) marks a position in the stream and, if necessary, creates a look-ahead buffer of the specified size. Future calls to reset( ) restore the stream to the marked position if they occur within the specified look-ahead limit. Note that not all stream types support this mark-and-reset functionality. To create a subclass of Reader, you need only implement the three-argument version of read( ) and the close( ) method. Most subclasses implement additional methods, however.

java.io.Reader

Figure 9-54. java.io.Reader

public abstract class Reader implements Closeable, Readable {
// Protected Constructors
     protected Reader( );  
     protected Reader(Object lock);  
// Public Instance Methods
     public abstract void close ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.