juju.reattore.io.impl
Class ByteBufferSource

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

public class ByteBufferSource
extends java.lang.Object
implements ByteSource

A thin wrapper around the ByteBuffer API that implements the Reattore IO API.


Field Summary
 
Fields inherited from interface juju.reattore.io.Source
EOF
 
Constructor Summary
protected ByteBufferSource()
          Internal constructor for derrivitaves that wish to set the buffer later.
  ByteBufferSource(byte[] wrap)
          Create a new source containing the given array data.
  ByteBufferSource(java.nio.ByteBuffer on)
          Create a new source wrapper around the given ByteBuffer.
 
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.
 java.nio.ByteBuffer getBackingBuffer()
          Gives direct access to the backing buffer of this source for copy operations.
 int remaining()
          Returns the number of elements remaining in the stream.
protected  void setBackingBuffer(java.nio.ByteBuffer on)
          Used by a derrivitave to set the backing buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferSource

public ByteBufferSource(java.nio.ByteBuffer on)
Create a new source wrapper around the given ByteBuffer.

Parameters:
on - Buffer to wrap.

ByteBufferSource

public ByteBufferSource(byte[] wrap)
Create a new source containing the given array data.

Parameters:
wrap - The data to contain.

ByteBufferSource

protected ByteBufferSource()
Internal constructor for derrivitaves that wish to set the buffer later.

Method Detail

setBackingBuffer

protected void setBackingBuffer(java.nio.ByteBuffer on)
Used by a derrivitave to set the backing buffer.

Parameters:
on - The buffer to run against.

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

getBackingBuffer

public java.nio.ByteBuffer getBackingBuffer()
Gives direct access to the backing buffer of this source for copy operations. If this class is fresh then the buffer is fresh, otherwise the state is undefined.

Returns:
The backing buffer.

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.