Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.io

Class PushbackReader

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


public class PushbackReader

extends FilterReader

This subclass of FilterReader provides the ability to unread data from a stream. It maintains an internal buffer of unread data that is supplied to the next read operation. This is conceptually similar to mark/reset functionality, except that in this case the position to reset the stream to does not need to be known in advance.

The default pushback buffer size one char, but this can be overridden by the creator of the stream.

Authors:

Constructor Summary

PushbackReader(java.io.Reader in)

This method initializes a PushbackReader to read from the specified subordinate Reader with a default pushback buffer size of 1.
PushbackReader(java.io.Reader in, int bufsize)

This method initializes a PushbackReader to read from the specified subordinate Reader with the specified buffer size

Method Summary

voidclose()

This method closes the stream and frees any associated resources.
voidmark(int read_limit)

This method throws an exception when called since this class does not support mark/reset.
booleanmarkSupported()

This method returns false to indicate that it does not support mark/reset functionality.
intread()

This method reads an unsigned char from the input stream and returns it as an int in the range of 0-65535.
synchronized intread(char[] b, int offset, int len)

This method read chars from a stream and stores them into a caller supplied buffer.
booleanready()

This method determines whether or not this stream is ready to be read.
voidreset()

This method always throws an IOException in this class because mark/reset functionality is not supported.
longskip(long num_chars)

This method skips the specified number of chars in the stream.
voidunread(int b)

This method pushes a single char of data into the pushback buffer.
synchronized voidunread(char[] buf)

This method pushes all of the chars in the passed char array into the pushback buffer.
synchronized voidunread(char[] b, int offset, int len)

This method pushed back chars from the passed in array into the pushback buffer.

Constructor Details

PushbackReader

public PushbackReader(java.io.Reader in)

This method initializes a PushbackReader to read from the specified subordinate Reader with a default pushback buffer size of 1.

Parameters:


PushbackReader

public PushbackReader(java.io.Reader in, int bufsize)

This method initializes a PushbackReader to read from the specified subordinate Reader with the specified buffer size

Parameters:


Method Details

close

public void close()

This method closes the stream and frees any associated resources.

Throws:


mark

public void mark(int read_limit)

This method throws an exception when called since this class does not support mark/reset.

Parameters:

Throws:


markSupported

public boolean markSupported()

This method returns false to indicate that it does not support mark/reset functionality.

Returns:


read

public int read()

This method reads an unsigned char from the input stream and returns it as an int in the range of 0-65535. This method also will return -1 if the end of the stream has been reached. The char returned will be read from the pushback buffer, unless the buffer is empty, in which case the char will be read from the underlying stream.

This method will block until the char can be read.

Returns:

Throws:


read

public synchronized int read(char[] b, int offset, int len)

This method read chars from a stream and stores them into a caller supplied buffer. It starts storing the data at index offset into the buffer and attempts to read len chars. This method can return before reading the number of chars requested. The actual number of chars read is returned as an int. A -1 is returned to indicate the end of the stream.

This method will block until some data can be read.

This method first reads chars from the pushback buffer in order to satisfy the read request. If the pushback buffer cannot provide all of the chars requested, the remaining chars are read from the underlying stream.

Parameters:

Returns:

Throws:


ready

public boolean ready()

This method determines whether or not this stream is ready to be read. If it returns false to indicate that the stream is not ready, any attempt to read from the stream could (but is not guaranteed to) block.

This stream is ready to read if there are either chars waiting to be read in the pushback buffer or if the underlying stream is ready to be read.

Returns:

Throws:


reset

public void reset()

This method always throws an IOException in this class because mark/reset functionality is not supported.

Throws:


skip

public long skip(long num_chars)

This method skips the specified number of chars in the stream. It returns the actual number of chars skipped, which may be less than the requested amount.

This method first discards chars from the buffer, then calls the skip method on the underlying Reader to skip additional chars if necessary.

Parameters:

Returns:

Throws:


unread

public synchronized void unread(char[] buf)

This method pushes all of the chars in the passed char array into the pushback buffer. These chars are pushed in reverse order so that the next char read from the stream after this operation will be buf[0] followed by buf[1], etc.

If the pushback buffer cannot hold all of the requested chars, an exception is thrown.

Parameters:

Throws:


unread

public synchronized void unread(char[] b, int offset, int len)

This method pushed back chars from the passed in array into the pushback buffer. The chars from buf[offset] to buf[offset + len] are pushed in reverse order so that the next char read from the stream after this operation will be buf[offset] followed by buf[offset + 1], etc.

If the pushback buffer cannot hold all of the requested chars, an exception is thrown.

Parameters:

Throws:


unread

public void unread(int b)

This method pushes a single char of data into the pushback buffer. The char pushed back is the one that will be returned as the first char of the next read.

If the pushback buffer is full, this method throws an exception.

The argument to this method is an int. Only the low eight bits of this value are pushed back.

Parameters:

Throws: