net.sf.mmm.util.io.api
Interface ComposedByteBuffer

All Superinterfaces:
ByteBuffer, ByteIterator, ByteProvider
All Known Subinterfaces:
DetectorStreamBuffer
All Known Implementing Classes:
AbstractByteArrayBufferBuffer, ByteArrayBufferBuffer, DetectorStreamBufferImpl, LookaheadByteArrayBufferBuffer

public interface ComposedByteBuffer
extends ByteBuffer

This is the interface of a ByteBuffer that is internally composed out of multiple ByteArrays. It allows to access these ByteArrays for read-only lookahead operations or more efficient processing.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Method Summary
 int fill(byte[] buffer, int offset, int length)
          This method fills the given buffer starting at offset with the next bytes from this ComposedByteBuffer.
 ByteArray getByteArray(int index)
          This method gets the ByteArray at the given index.
 int getByteArrayCount()
          This method gets the number of ByteArrays currently available via getByteArray(int).
 
Methods inherited from interface net.sf.mmm.util.io.api.ByteIterator
hasNext, next, peek, skip
 
Methods inherited from interface net.sf.mmm.util.io.api.ByteProvider
getBytesAvailable
 

Method Detail

getByteArray

ByteArray getByteArray(int index)
This method gets the ByteArray at the given index. The DetectorStreamBuffer is composed out of ByteArrays. This method allows efficient processing of bytes from byte[] rather then calling ByteIterator.hasNext() and ByteIterator.next() and repetitive. Additionally this way allows full lookahead up to the end of the buffer without consuming the data.
ATTENTION:
Consuming operations such as ByteIterator.next() or ByteIterator.skip(long) will invalidate the returned ByteArray. Please do NOT call these methods while working with ByteArrays.

Parameters:
index - is the index of the requested ByteArray. It has to be in the range from 0 to getByteArrayCount() - 1. A value of 0 indicates the current ByteArray this buffer is currently pointing to. For that current buffer ByteArray.getBytes()[ByteArray.getCurrentIndex()] will have the same result as ByteIterator.peek().
Returns:
the requested ByteArray.
See Also:
getByteArrayCount()

getByteArrayCount

int getByteArrayCount()
This method gets the number of ByteArrays currently available via getByteArray(int).
ATTENTION:
Consuming operations such as ByteIterator.next() or ByteIterator.skip(long) will invalidate the returned ByteArray. Please do NOT call these methods while working with ByteArrays.

Returns:
the number of currently available ByteArrays.

fill

int fill(byte[] buffer,
         int offset,
         int length)
This method fills the given buffer starting at offset with the next bytes from this ComposedByteBuffer. The bytes that are filled into the given buffer will therefore be consumed. This method can be used to write data from this buffer to an OutputStream or supply it to the consumer of an InputStream.

Parameters:
buffer - is the buffer to fill.
offset - is the index in the given buffer where to fill in the first byte. See ByteArray.getCurrentIndex().
length - is the expected number of bytes to fill into buffer. Has to be positive and less or equal to buffer.length - offset. However at most the number of available bytes can be filled even if length is greater.
Returns:
the number of bytes that have actually been filled into the buffer. Will be positive and less or equal to the given length. Should be only less than maxLength if NOT enough bytes are available.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.