java.io
Class PushbackReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--java.io.FilterReader
              |
              +--java.io.PushbackReader

public class PushbackReader
extends FilterReader

Untamed: A character-stream reader that allows characters to be pushed back into the stream.

Since:
JDK1.1
Version:
1.15, 01/12/03
Author:
Mark Reinhold

Field Summary
private  char[] buf
          Pushback buffer
private  int pos
          Current position in buffer
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
PushbackReader(Reader in)
          Enabled: Create a new pushback reader with a one-character pushback buffer.
PushbackReader(Reader in, int size)
          Enabled: Create a new pushback reader with a pushback buffer of the given size.
 
Method Summary
 void close()
          Enabled: Close the stream.
private  void ensureOpen()
          Check to make sure that the stream has not been closed.
 void mark(int readAheadLimit)
          Enabled: Mark the present position in the stream.
 boolean markSupported()
          Enabled: Tell whether this stream supports the mark() operation, which it does not.
 int read()
          Enabled: Read a single character.
 int read(char[] cbuf, int off, int len)
          Enabled: Read characters into a portion of an array.
 boolean ready()
          Enabled: Tell whether this stream is ready to be read.
 void reset()
          Enabled: Reset the stream.
 void unread(char[] cbuf)
          Enabled: Push back an array of characters by copying it to the front of the pushback buffer.
 void unread(char[] cbuf, int off, int len)
          Enabled: Push back a portion of an array of characters by copying it to the front of the pushback buffer.
 void unread(int c)
          Enabled: Push back a single character.
 
Methods inherited from class java.io.FilterReader
skip
 
Methods inherited from class java.io.Reader
getText, getTwine, iterate, iterate, read, readChar, readString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

private char[] buf
Pushback buffer


pos

private int pos
Current position in buffer

Constructor Detail

PushbackReader

public PushbackReader(Reader in,
                      int size)
Enabled: Create a new pushback reader with a pushback buffer of the given size.

Parameters:
in - The reader from which characters will be read
size - The size of the pushback buffer

PushbackReader

public PushbackReader(Reader in)
Enabled: Create a new pushback reader with a one-character pushback buffer.

Parameters:
in - The reader from which characters will be read
Method Detail

ensureOpen

private void ensureOpen()
                 throws IOException
Check to make sure that the stream has not been closed.

IOException

read

public int read()
         throws IOException
Enabled: Read a single character.

Overrides:
read in class FilterReader
Returns:
The character read, or -1 if the end of the stream has been reached
IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Enabled: Read characters into a portion of an array.

Overrides:
read in class FilterReader
Parameters:
cbuf - Destination buffer
off - Offset at which to start writing 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
IOException

unread

public void unread(int c)
            throws IOException
Enabled: Push back a single character.

Parameters:
c - The character to push back
IOException

unread

public void unread(char[] cbuf,
                   int off,
                   int len)
            throws IOException
Enabled: Push back a portion of an array of characters by copying it to the front of the pushback buffer. After this method returns, the next character to be read will have the value cbuf[off], the character after that will have the value cbuf[off+1], and so forth.

Parameters:
cbuf - Character array
off - Offset of first character to push back
len - Number of characters to push back
IOException

unread

public void unread(char[] cbuf)
            throws IOException
Enabled: Push back an array of characters by copying it to the front of the pushback buffer. After this method returns, the next character to be read will have the value cbuf[0], the character after that will have the value cbuf[1], and so forth.

Parameters:
cbuf - Character array to push back
IOException

ready

public boolean ready()
              throws IOException
Enabled: Tell whether this stream is ready to be read.

Overrides:
ready in class FilterReader
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.
IOException

mark

public void mark(int readAheadLimit)
          throws IOException
Enabled: Mark the present position in the stream. The mark for class PushbackReader always throws an exception.

Overrides:
mark in class FilterReader
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.
IOException

reset

public void reset()
           throws IOException
Enabled: Reset the stream. The reset method of PushbackReader always throws an exception.

Overrides:
reset in class FilterReader
IOException

markSupported

public boolean markSupported()
Enabled: Tell whether this stream supports the mark() operation, which it does not.

Overrides:
markSupported in class FilterReader
Returns:
true if and only if this stream supports the mark operation.

close

public void close()
           throws IOException
Enabled: Close the stream.

Overrides:
close in class FilterReader
IOException


comments?