Sharkysoft home

lava.io
Class UnlimitedPushbackReader

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

public class UnlimitedPushbackReader
extends java.io.PushbackReader

"Pushbackable" input stream with no pushback limit.

Details: This class is similar to java.io.PushbackReader, except that no limit is imposed on the number of characters that can be pushed back. Additionally, the unread methods can process either characters or whole strings.

Since:
1998.02.22
Version:
2000.06.03

Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
UnlimitedPushbackReader(java.io.Reader reader)
          Converts a Reader to an UnlimitedPushbackReader.
 
Method Summary
 void close()
           
 boolean eof()
          Tells if the end-of-stream has been reached.
 void mark(int read_ahead_limit)
          Marks the present position.
 int peek()
          Previews the next character.
 int read()
          Reads the next character.
 int read(char[] dest)
           
 int read(char[] dest, int off, int len)
          Reads a block of characters.
 void reset()
          Restores this stream to the previously marked state.
 void unread(char[] src)
           
 void unread(char[] src, int off, int len)
           
 void unread(int c)
          Pushes a character back to the stream.
 void unread(java.lang.String s)
          Pushes a String back to the stream.
 
Methods inherited from class java.io.PushbackReader
markSupported, ready
 
Methods inherited from class java.io.FilterReader
skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnlimitedPushbackReader

public UnlimitedPushbackReader(java.io.Reader reader)
Converts a Reader to an UnlimitedPushbackReader.
Parameters:
reader - the Reader
Since:
1998
Method Detail

read

public int read()
         throws java.io.IOException
Reads the next character.

Details: read reads the next character from the stream and returns it. If the end-of-stream has been reached, -1 is returned.

Overrides:
read in class java.io.PushbackReader
Returns:
the character read
Throws:
java.io.IOException - if an I/O error occurs
Since:
1998

read

public final int read(char[] dest)
               throws java.io.IOException
Overrides:
read in class java.io.Reader

read

public int read(char[] dest,
                int off,
                int len)
         throws java.io.IOException
Reads a block of characters.

Details: This method reads a block of characters from this stream, filling dest, the supplied destination buffer. len characters are written into dest begining at offset off. If no characters can be read before encountering the end-of-stream, -1 is returned. Otherwise, the number of characters read and stored in buff is returned. Note that if end-of-stream is reached while filling the buffer, this value may be less than len.

Overrides:
read in class java.io.PushbackReader
Parameters:
dest - the destination buffer
off - offset into dest
len - number of characters to read
Returns:
number of characters read and stored
Throws:
java.io.IOException - if an I/O error occurs
Since:
1998

peek

public int peek()
         throws java.io.IOException
Previews the next character.

Details: peek reads and unreads the next character, and then returns its value.

Calls: read(), unread(int)

Returns:
the character read
Throws:
java.io.IOException - if an I/O error occurs
Since:
1998

unread

public void unread(int c)
            throws java.io.IOException
Pushes a character back to the stream.

Details: unread pushes a character back onto the stream. Subsequent calls to read will retrieve it. Unreading an EOF is allowed and has no effect.

Overrides:
unread in class java.io.PushbackReader
Parameters:
c - the character
Since:
1998

unread

public final void unread(char[] src)
                  throws java.io.IOException
Overrides:
unread in class java.io.PushbackReader

unread

public void unread(char[] src,
                   int off,
                   int len)
            throws java.io.IOException
Overrides:
unread in class java.io.PushbackReader

unread

public void unread(java.lang.String s)
            throws java.io.IOException
Pushes a String back to the stream.

Details: unread pushes a String back onto the stream. Subsequent calls to read will retrieve its characters. Unreading null is allowed and has no effect.

Parameters:
s - the String
Since:
1998

mark

public void mark(int read_ahead_limit)
          throws java.io.IOException
Marks the present position.

Details: mark marks the present position in this stream. Subsequent calls to reset will attempt to restore the stream to the state it was at when mark was last called. There is a limit on how many characters can be read (read_ahead_limit), after calling mark, before calls to reset are no longer guaranteed to be successful. Not all streams support mark. This stream supports mark if the base stream supports mark.

Overrides:
mark in class java.io.PushbackReader
Parameters:
read_ahead_limit - number of characters that can be read after mark before reset-ability is compromised
Throws:
java.io.IOException - if the stream cannot be marked
Since:
1998

reset

public void reset()
           throws java.io.IOException
Restores this stream to the previously marked state.

Details: reset attempts to restore the stream to the state it was in during the most recent call to mark. If mark has not been previously called, then reset will attempt to reset this stream in a manner that is appropriate for this particular type of stream. Not all streams support reset. This stream supports reset if the base stream supports reset.

Overrides:
reset in class java.io.PushbackReader
Throws:
java.io.IOException - if the stream cannot be reset
Since:
1998

eof

public boolean eof()
            throws java.io.IOException
Tells if the end-of-stream has been reached.

Details: eof calls peek to see if another character is available in the stream. If the end-of-stream has been reached, peek returns true, otherwise false.

Technically, this method checks for end-of-stream, not end-of-file, since the base stream may not originate from a file. This method is named "eof" for traditional reasons.

Calls: peek()

Returns:
true iff the end-of-stream has been reached
Throws:
java.io.IOException - if an I/O error occurs
Since:
1998

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.PushbackReader

Sharkysoft home