juju.reattore.io.impl
Class ByteSourceSink

java.lang.Object
  |
  +--juju.reattore.io.impl.ByteSourceSink
All Implemented Interfaces:
ByteSink, ByteSource, java.lang.Comparable, Sink, Source

public class ByteSourceSink
extends java.lang.Object
implements ByteSource, ByteSink, java.lang.Comparable

Buffer that may be used for temporary storage and which is backed by a byte array. Used for storing an incomming stream for later use. Concurrent read/write access is unpredictable. Concurrent read access shares the same stream position and marks.


Field Summary
 
Fields inherited from interface juju.reattore.io.Source
EOF
 
Constructor Summary
ByteSourceSink()
          Creates a new, empty source/sink
ByteSourceSink(byte[] initial)
          Creates a new source/sink and populates it.
 
Method Summary
 byte[] array()
          Returns the array backing this source/sink.
 void compact()
          Compacts the backing buffer to comtain just the data.
 int compareTo(java.lang.Object ob)
          Compares this stream to a byte array.
 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 mark()
           
 void put(byte[] from, int offset, int length)
          Bulk put operation.
 void put(int toWrite)
          Writes a byte to the stream.
 int remaining()
          Returns the number of elements remaining in the stream.
 void reset()
           
 void rewind()
           
 int size()
          Returns the number of elements in the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteSourceSink

public ByteSourceSink()
Creates a new, empty source/sink


ByteSourceSink

public ByteSourceSink(byte[] initial)
Creates a new source/sink and populates it. Inefficient. For convenience only.

Parameters:
initial - Initial data to populate the source with.
Method Detail

mark

public void mark()
See Also:
Source

reset

public void reset()
See Also:
Source

rewind

public void rewind()
See Also:
Source

get

public int get()
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.
See Also:
ByteSource

get

public int get(byte[] into,
               int offset,
               int length)
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.
See Also:
ByteSource

remaining

public int remaining()
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.
See Also:
ByteSource

put

public void put(int toWrite)
Description copied from interface: ByteSink
Writes a byte to the stream.

Specified by:
put in interface ByteSink
Parameters:
toWrite - The byte to write.
See Also:
ByteSink

put

public void put(byte[] from,
                int offset,
                int length)
Description copied from interface: ByteSink
Bulk put operation.

Specified by:
put in interface ByteSink
Parameters:
from - The buffer to copy from.
offset - The offset in the buffer to begin reading from.
length - The number of elements to write.
See Also:
ByteSink

size

public int size()
Description copied from interface: ByteSink
Returns the number of elements in the stream.

Specified by:
size in interface ByteSink
Returns:
Number of elements in the stream.
See Also:
ByteSink

compact

public void compact()
Compacts the backing buffer to comtain just the data.


array

public byte[] array()
Returns the array backing this source/sink.

Returns:
The backing array.

compareTo

public int compareTo(java.lang.Object ob)
Compares this stream to a byte array. ByteSourceSink. Primarialy used for equivalence tests in the test libs. This instance is equivalent to a byte array if it contains the same number of bytes and if every byte is the same.

Specified by:
compareTo in interface java.lang.Comparable
See Also:
Object#compareTo

dispose

public void dispose()
Description copied from interface: Source
Called when the user is finished with this source. The source is invalid after this call.

Specified by:
dispose in interface Source
See Also:
Source


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