|
Chapter 11 The java.io Package |
|
PushbackReader
Name
PushbackReader
- Class Name:
-
java.io.PushbackReader
- Superclass:
-
java.io.FilterReader
- Immediate Subclasses:
-
None
- Interfaces Implemented:
-
None
- Availability:
-
New as of JDK 1.1
The PushbackReader class represents a character
stream that allows data to be pushed back into the stream. In other
words, after data has been read from a
PushbackReader, it can be pushed back into the
stream so that it can be reread. This functionality is useful for
implementing things like parsers that need to read data and then
return it to the input stream. PushbackReader is
the character-oriented equivalent of
PushbackInputStream.
public class java.io.PushbackReader extends java.io.FilterReader {
// Constructors
public PushbackReader(Reader in);
public PushbackReader(Reader in, int size);
// Instance Methods
public void close();
public boolean markSupported();
public int read();
public int read(char[] cbuf, int off, int len);
public boolean ready();
public void unread(int c);
public void unread(char[] cbuf);
public void unread(char[] cbuf, int off, int len);
}
- Parameters
-
- in
-
The reader to wrap.
- Description
-
This constructor creates a PushbackReader
that reads from the given Reader,
using a pushback buffer with the default size of one byte.
- Parameters
-
- in
-
The reader to wrap.
- size
-
The size of the pushback buffer.
- Description
-
This constructor creates a PushbackReader
that reads from the given Reader,
using a pushback buffer of the given size.
- Throws
-
- IOException
-
If any kind
of I/O error occurs.
- Overrides
-
FilterReader.close()
- Description
-
This method closes the reader and releases the system resources that are
associated with it.
- Returns
-
The boolean value false.
- Overrides
-
FilterReader.markSupported()
- Description
-
This method returns false to
indicate that this class does not support mark()
and reset().
- Returns
-
The next character of data or -1 if the end of the stream is encountered.
- Throws
-
- IOException
-
If any kind
of I/O error occurs.
- Overrides
-
FilterReader.read()
- Description
-
This method reads a character of data. If there is any data in the pushback
buffer, the method returns the next character in the pushback buffer. Otherwise,
it calls the read() method
of the underlying stream. The method blocks until the character is read,
the end of the stream is encountered, or an exception is thrown.
- Parameters
-
- cbuf
-
An array of characters to be filled from the stream.
- off
-
An offset into the array.
- len
-
The number of characters to read.
- Returns
-
The actual number of characters read or -1 if the end of the stream is
encountered immediately.
- Throws
-
- IOException
-
If any kind
of I/O error occurs.
- Overrides
-
FilterReader.read(char[], int, int)
- Description
-
This method copies characters from the stream into the given array cbuf,
starting at index off and continuing
for len characters. If the
array can be populated solely from the pushback buffer, the method returns
immediately. Otherwise, the read(char[],
int, int)
method of the underlying stream is called to make up the difference. The
method blocks until some data is available.
- Returns
-
A boolean value that indicates
whether the stream is ready to be read.
- Throws
-
- IOException
-
If the stream
is closed.
- Overrides
-
FilterReader.ready()
- Description
-
If there is data in the pushback buffer, or if the underlying stream is
ready, this method returns true.
The underlying stream is ready if the next read() is
guaranteed not to block.
- Parameters
-
- c
-
The value to push back.
- Throws
-
- IOException
-
If
the pushback buffer is full.
- Description
-
This method puts the given character into the pushback buffer.
- Parameters
-
- cbuf
-
An array of characters
to push back.
- Throws
-
- IOException
-
If
the pushback buffer is full.
- Description
-
This method puts all of the characters in the given array into the pushback
buffer.
- Parameters
-
- cbuf
-
An array of characters to push back.
- off
-
An offset into the array.
- len
-
The number of characters to push back.
- Throws
-
- IOException
-
If
the pushback buffer is full.
- Description
-
This method puts len characters
from the given array, starting at offset off,
into the pushback buffer.
FilterReader,
IOException,
Reader
|
|