juju.reattore.io.impl
Class PushbackByteSource

java.lang.Object
  |
  +--juju.reattore.io.impl.PushbackByteSource
All Implemented Interfaces:
ByteSource, Source

public class PushbackByteSource
extends java.lang.Object
implements ByteSource

Simple one character pushback system that works across multiple input arrays.


Field Summary
 
Fields inherited from interface juju.reattore.io.Source
EOF
 
Constructor Summary
PushbackByteSource()
          Create a new source to be seed()ed later on.
PushbackByteSource(ByteSource on)
          Create a new source around the given source.
 
Method Summary
 void dispose()
          Called when the user is finished with this source.
 int get()
          Gets the next byte from the stream.
 int get(byte[] into, int offset, int length)
          Bulk get operation.
 void pushback(int b)
          Returns the given byte back to the input.
 int remaining()
          Returns the number of elements remaining in the stream.
 void seed(ByteSource on)
          Seeds the push back system with a new array to read from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushbackByteSource

public PushbackByteSource()
Create a new source to be seed()ed later on.


PushbackByteSource

public PushbackByteSource(ByteSource on)
Create a new source around the given source.

Parameters:
on - The source to wrap.
Method Detail

seed

public void seed(ByteSource on)
Seeds the push back system with a new array to read from. Does not discard any existing push back.

Parameters:
on - The source to read from.

dispose

public void dispose()
Called when the user is finished with this source. The source is invalid after this call.

Specified by:
dispose in interface Source

get

public int get()
        throws java.io.IOException
Description copied from interface: ByteSource
Gets the next byte from the stream.

Specified by:
get in interface ByteSource
Returns:
The next byte, or EOF on end of stream.
Throws:
java.io.IOException - on error.
See Also:
Source

get

public int get(byte[] into,
               int offset,
               int length)
        throws java.io.IOException
Description copied from interface: ByteSource
Bulk get operation.

Specified by:
get in interface ByteSource
Parameters:
into - The buffer to get into.
offset - The offset in the buffer to begin writing at.
length - The maximum number of elements to read.
Returns:
The number of elements read.
Throws:
java.io.IOException - on error.
See Also:
Source

remaining

public int remaining()
              throws java.io.IOException
Description copied from interface: ByteSource
Returns the number of elements remaining in the stream.

Specified by:
remaining in interface ByteSource
Returns:
Number remaining, or a negative number if it is unknown.
Throws:
java.io.IOException - on error.
See Also:
Source

pushback

public void pushback(int b)
Returns the given byte back to the input. The next call to get() will return this.

Parameters:
b - Any byte. Does not have to have been read.


Copyright © 2002-2003 Michael Hope. All Rights Reserved.