com.ibm.wbi
Interface ByteStore

All Known Implementing Classes:
ByteBuffer, ByteBufferUnsynchronized

public interface ByteStore

The ByteStore provides a generic interface for an object used to store bytes. The ByteStore is used as the middle byte storing mechanism between Megs. A custom implementation of the ByteStore interface can be provided by a Sublayer to provide altered behavior for dealing with the bytes streamed between Megs. For example, a ByteStore could be written to store bytes to disk if a limiting high water mark is reached to conserve on memory usage.


Method Summary
 void append(byte val)
          Appends the given byte argument to this ByteStore.
 void append(byte[] bytes)
          Appends the given byte array argument to this buffer.
 void append(byte[] bytes, int offset, int length)
          Appends the given byte subarray of the bytes array argument to this buffer.
 byte byteAt(int index)
          Returns the byte at a specific index in this ByteStore.
 int capacity()
          Returns the current capacity of the ByteStore.
 void ensureCapacity(int minimumCapacity)
          Ensures that the capacity of the buffer is at least equal to the specified minimum.
 byte[] getByteArrayRef()
          Return a byte array of the current buffer size containing the bytes.
 byte[] getBytes()
          Return a byte array of the current buffer size containing the bytes.
 void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
          Populate the given byte buffer by the specified bytes.
 void insert(int offset, byte val)
          Inserts the given byte argument into this ByteStore.
 void insert(int offset, byte[] bytes)
          Inserts the given byte array argument into this ByteStore.
 int length()
          Returns the length of this ByteStore.
 void purge()
          The current contents are released leaving an empty ByteStore
 void purge(int capacity)
          The current contents are released and an empty ByteStore with the specified capacity is created.
 void setByteAt(int index, byte val)
          The byte at the specified index of this ByteStore is set to val .
 void setLength(int newLength)
          Sets the length of this ByteStore.
 int size()
          Returns the length of this ByteStore.
 

Method Detail

purge

public void purge()
The current contents are released leaving an empty ByteStore

purge

public void purge(int capacity)
The current contents are released and an empty ByteStore with the specified capacity is created.
Parameters:
capacity - The initial capacity.

length

public int length()
Returns the length of this ByteStore.
Returns:
The number of bytes in the ByteStore.

size

public int size()
Returns the length of this ByteStore. This method should return the same information as length().
Returns:
The number of bytes in the ByteBuffer.

capacity

public int capacity()
Returns the current capacity of the ByteStore.
Returns:
The current capacity of this ByteStore.

ensureCapacity

public void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum. If the minimumCapacity argument is nonpositive, this method takes no action and simply returns.
Parameters:
minimumCapacity - The minimum desired capacity.

setLength

public void setLength(int newLength)
               throws java.lang.StringIndexOutOfBoundsException
Sets the length of this ByteStore. If the newLength argument is less than the current length of the ByteStore, the ByteBuffer is truncated to contain exactly the number of characters given by the newLength argument.

If the newLength argument is greater than or equal to the current length, sufficient null bytes will be appended to the byte buffer so that length becomes equal to the newLength argument.

The newLength argument must be greater than or equal to 0.

Parameters:
newLength - The new length of the buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - The newLength argument is invalid

byteAt

public byte byteAt(int index)
            throws java.lang.ArrayIndexOutOfBoundsException
Returns the byte at a specific index in this ByteStore.

The first byte of the ByteStore is considered to be at index 0, the next at index 1, and so on, for array indexing.

The index argument must be greater than or equal to 0, and less than the length of this ByteStore.

Parameters:
index - The index of the desired byte.
Returns:
The byte at the specified index of this ByteBuffer.
Throws:
java.lang.ArrayIndexOutOfBoundsException - The index is invalid.

getBytes

public byte[] getBytes()
Return a byte array of the current buffer size containing the bytes. The returned array will be newly created with a copy of the buffered bytes.
Returns:
A byte array with a length equal to the length of the buffered array, containing the buffered bytes.

getByteArrayRef

public byte[] getByteArrayRef()
Return a byte array of the current buffer size containing the bytes. Implementing classes can use this method as a performance enhancement since they have the option of returning the internal structure instead of copying it. The effects of modifying the returned buffer are undefined and may or may not change the underlying byte store. The returned array should therefore by treated as constant and immutable.
Returns:
A byte array with a length equal to the length of the buffered array, containing the buffered bytes.

getBytes

public void getBytes(int srcBegin,
                     int srcEnd,
                     byte[] dst,
                     int dstBegin)
              throws java.lang.ArrayIndexOutOfBoundsException
Populate the given byte buffer by the specified bytes.
Parameters:
srcBegin - The beginning source index.
srcEnd - The ending source index.
dst - The destination buffer.
dstBegin - The beginning index in the destination buffer.
Throws:
java.lang.ArrayIndexOutOfBoundsException - The index is invalid.

setByteAt

public void setByteAt(int index,
                      byte val)
               throws java.lang.ArrayIndexOutOfBoundsException
The byte at the specified index of this ByteStore is set to val .
Parameters:
index - The index of the byte to overwrite.
val - The new byte value.
Throws:
java.lang.ArrayIndexOutOfBoundsException - The index is invalid.

append

public void append(byte val)
Appends the given byte argument to this ByteStore.

The argument is appended to the contents of this ByteStore. The length of this ByteStore increases by 1.

Parameters:
val - A byte value.

append

public void append(byte[] bytes)
Appends the given byte array argument to this buffer.

The bytes of the array argument are appended, in order, to the contents of this ByteStore.

Parameters:
bytes - The bytes to be appended.

append

public void append(byte[] bytes,
                   int offset,
                   int length)
Appends the given byte subarray of the bytes array argument to this buffer.

Bytes of the byte array bytes, starting at index offset, are appended, in order, to the contents of this byte buffer.

Parameters:
bytes - The bytes to be appended.
offset - The index of the first byte to append.
length - The number of bytes to append.

insert

public void insert(int offset,
                   byte[] bytes)
            throws java.lang.ArrayIndexOutOfBoundsException
Inserts the given byte array argument into this ByteStore.

The bytes of the array argument are inserted into the contents of this ByteStore at the position indicated by offset.

Parameters:
offset - The offset.
bytes - A byte array.
Throws:
java.lang.ArrayIndexOutOfBoundsException - There is an invalid index into the buffer.

insert

public void insert(int offset,
                   byte val)
Inserts the given byte argument into this ByteStore.

The second argument is inserted into the contents of this byte buffer at the position indicated by offset. The length of this ByteStore increases by one.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this ByteBuffer.

Parameters:
offset - The offset.
val - The byte value.