Top Description Fields Constructors Methods
java.io

public Class PushbackReader

extends FilterReader
Class Inheritance
Imports
java.util.Objects

A character-stream reader that allows characters to be pushed back into the stream.
Author
Mark Reinhold
Since
1.1

Field Summary

Modifier and TypeField and Description
private char[]
buf

Pushback buffer

private int
pos

Current position in buffer

Inherited from java.io.FilterReader:
in

Constructor Summary

AccessConstructor and Description
public
PushbackReader(Reader
The reader from which characters will be read
in
,
int
The size of the pushback buffer
size
)

Creates a new pushback reader with a pushback buffer of the given size.

public
PushbackReader(Reader
The reader from which characters will be read
in
)

Creates a new pushback reader with a one-character pushback buffer.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterReader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

private void
ensureOpen()

Checks to make sure that the stream has not been closed.

public void
mark(int
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.
readAheadLimit
)

Overrides java.io.FilterReader.mark.

Marks the present position in the stream.

public boolean
markSupported()

Overrides java.io.FilterReader.markSupported.

Tells whether this stream supports the mark() operation, which it does not.

public int

Returns:

The character read, or -1 if the end of the stream has been reached
read
()

Overrides java.io.FilterReader.read.

Reads a single character.

public int
read(char[]
Destination buffer
cbuf
,
int
Offset at which to start storing characters
off
,
int
Maximum number of characters to read
len
)

Overrides java.io.FilterReader.read.

Reads characters into a portion of an array.

public boolean
ready()

Overrides java.io.FilterReader.ready.

Tells whether this stream is ready to be read.

public void
reset()

Overrides java.io.FilterReader.reset.

Resets the stream.

public long
skip(long
The number of characters to skip
n
)

Overrides java.io.FilterReader.skip.

Skips characters.

public void
unread(int
The int value representing a character to be pushed back
c
)

Pushes back a single character by copying it to the front of the pushback buffer.

public void
unread(char[]
Character array
cbuf
,
int
Offset of first character to push back
off
,
int
Number of characters to push back
len
)

Pushes back a portion of an array of characters by copying it to the front of the pushback buffer.

public void
unread(char[]
Character array to push back
cbuf
)

Pushes back an array of characters by copying it to the front of the pushback buffer.

Field Detail

bufback to summary
private char[] buf

Pushback buffer

posback to summary
private int pos

Current position in buffer

Constructor Detail

PushbackReaderback to summary
public PushbackReader(Reader in, int size)

Creates a new pushback reader with a pushback buffer of the given size.

Parameters
in:Reader

The reader from which characters will be read

size:int

The size of the pushback buffer

Exceptions
IllegalArgumentException:
if size <= 0
PushbackReaderback to summary
public PushbackReader(Reader in)

Creates a new pushback reader with a one-character pushback buffer.

Parameters
in:Reader

The reader from which characters will be read

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterReader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), unread(), ready(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect. This method will block while there is another thread blocking on the reader.

Exceptions
IOException:
If an I/O error occurs
ensureOpenback to summary
private void ensureOpen() throws IOException

Checks to make sure that the stream has not been closed.

markback to summary
public void mark(int readAheadLimit) throws IOException

Overrides java.io.FilterReader.mark.

Marks the present position in the stream. The mark for class PushbackReader always throws an exception.

Parameters
readAheadLimit:int

Doc from java.io.Reader.mark.

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.

Exceptions
IOException:
Always, since mark is not supported
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterReader.markSupported.

Tells whether this stream supports the mark() operation, which it does not.

Returns:boolean

Doc from java.io.Reader.markSupported.

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

readback to summary
public int read() throws IOException

Overrides java.io.FilterReader.read.

Reads a single character.

Returns:int

The character read, or -1 if the end of the stream has been reached

Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(char[] cbuf, int off, int len) throws IOException

Overrides java.io.FilterReader.read.

Doc from java.io.FilterReader.read.

Reads 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.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Doc from java.io.Reader.read.

Destination buffer

off:int

Doc from java.io.Reader.read.

Offset at which to start storing characters

len:int

Doc from java.io.Reader.read.

Maximum number of characters to read

Returns:int

Doc from java.io.Reader.read.

The number of characters read, or -1 if the end of the stream has been reached

Exceptions
IOException:

Doc from java.io.Reader.read.

If an I/O error occurs

readyback to summary
public boolean ready() throws IOException

Overrides java.io.FilterReader.ready.

Tells whether this stream is ready to be read.

Returns:boolean

Doc from java.io.Reader.ready.

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.

Exceptions
IOException:
If an I/O error occurs
resetback to summary
public void reset() throws IOException

Overrides java.io.FilterReader.reset.

Resets the stream. The reset method of PushbackReader always throws an exception.

Exceptions
IOException:
Always, since reset is not supported
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.FilterReader.skip.

Doc from java.io.FilterReader.skip.

Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. If the stream is already at its end before this method is invoked, then no characters are skipped and zero is returned.

Parameters
n:long

Doc from java.io.Reader.skip.

The number of characters to skip

Returns:long

Doc from java.io.Reader.skip.

The number of characters actually skipped

Exceptions
IOException:

Doc from java.io.Reader.skip.

If an I/O error occurs

unreadback to summary
public void unread(int c) throws IOException

Pushes back a single character by copying it to the front of the pushback buffer. After this method returns, the next character to be read will have the value (char)c.

Parameters
c:int

The int value representing a character to be pushed back

Exceptions
IOException:
If the pushback buffer is full, or if some other I/O error occurs
unreadback to summary
public void unread(char[] cbuf, int off, int len) throws IOException

Pushes 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:char[]

Character array

off:int

Offset of first character to push back

len:int

Number of characters to push back

Exceptions
IOException:
If there is insufficient room in the pushback buffer, or if some other I/O error occurs
unreadback to summary
public void unread(char[] cbuf) throws IOException

Pushes 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:char[]

Character array to push back

Exceptions
IOException:
If there is insufficient room in the pushback buffer, or if some other I/O error occurs