public abstract class AbstractByteArrayBufferBuffer extends Object implements ProcessableByteArrayBuffer, ComposedByteBuffer
ProcessableByteArrayBuffer interface for a byte[]
-Buffer that represents the concatenation of multiple ByteArrayBufferImpls. It has its own state
(read-pointer) and does NOT modify a contained buffer when reading. If one of the
underlying buffers has been read to the end
this class steps to the next one in a rotating way until the last buffer has been reached, that contains data that
has NOT been read before. Further this class allows to be (re)filled. | Modifier and Type | Field and Description |
|---|---|
private ByteArrayBufferImpl[] |
buffers
The actual buffers.
|
private int |
buffersEndIndex
The index of the last buffer out of
buffers. |
private int |
buffersIndex
The index of the current buffer out of
buffers. |
private int |
bufferStepCount
The number of buffers that have been stepped through.
|
private byte[] |
currentBufferBytes
The value of
. |
private int |
currentBufferIndex
The current position in
. |
private int |
currentBufferMax
The value of
. |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractByteArrayBufferBuffer(AbstractByteArrayBufferBuffer template)
The constructor used to copy from the given
template. |
|
AbstractByteArrayBufferBuffer(ByteArrayBufferImpl... buffers)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
fill(byte[] buffer,
int offset,
int length)
This method fills the given
buffer starting at offset with the next bytes from this
ComposedByteBuffer. |
protected boolean |
fill(InputStream inputStream)
This method fills this buffer using the given
inputStream. |
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 ComposedByteBuffer.getByteArray(int). |
int |
getBytesAvailable()
This method gets the number of bytes available.
|
protected ByteArrayBuffer |
getCurrentBuffer()
This method gets the current
ByteArrayBufferImpl. |
protected int |
getCurrentBufferIndex()
This method gets the current index in the
current buffer. |
boolean |
hasNext()
This method determines if there is a
next byte available. |
byte |
next()
This method gets the current byte in the iteration.
|
protected boolean |
nextBuffer()
This method switches the
current buffer to the next available buffer. |
byte |
peek()
This method gets the current byte in the iteration.
|
long |
process(ByteProcessor processor,
long byteCount)
This method processes the number of bytes given by
length (as far as available) using the given
processor. |
long |
skip(long byteCount)
This method skips the number of bytes given by
byteCount. |
protected void |
sync(AbstractByteArrayBufferBuffer master)
This method synchronizes the buffer with the given
master. |
private final ByteArrayBufferImpl[] buffers
private int buffersIndex
buffers.private int buffersEndIndex
buffers.private int bufferStepCount
private int currentBufferIndex
buffers[buffersIndex].private int currentBufferMax
buffers[buffersIndex].getMaximumIndex()
.private byte[] currentBufferBytes
buffers[buffersIndex].getBytes()
.public AbstractByteArrayBufferBuffer(ByteArrayBufferImpl... buffers)
buffers - are the buffers to concat.protected AbstractByteArrayBufferBuffer(AbstractByteArrayBufferBuffer template)
template.template - is the buffer to copy.protected ByteArrayBuffer getCurrentBuffer()
ByteArrayBufferImpl.ByteArrayBufferImpl.protected int getCurrentBufferIndex()
current buffer.current buffer.protected boolean nextBuffer()
current buffer to the next available buffer. If this method is
called when the last buffer has already been reached, the index will be set to
getCurrentBuffer().getMaximumIndex()+1 so the
end of this buffer is reached and hasNext() will return false.true if there was a next buffer to switch to, false if the current buffer is already the last one.public int getBytesAvailable()
ByteProvidergetBytesAvailable in interface ByteProviderpublic boolean hasNext()
ByteIteratornext byte available.hasNext in interface ByteIteratortrue if there is a next byte available, false otherwise (if the end of this
buffer has been reached).public byte next()
throws NoSuchElementException
ByteIteratorByteIterator points
to the next byte in the iteration or to the end if there is no such byte available. ByteIterator.hasNext() returns true.next in interface ByteIteratorNoSuchElementException - if there is no such byte available.Iterator.next()public byte peek()
throws NoSuchElementException
ByteIteratorByteIterator.next() this method does NOT modify the state of
this ByteIterator. Therefore the peeked byte does NOT get consumed and repetitive calls will return the
same value. ByteIterator.hasNext() returns true.peek in interface ByteIteratorNoSuchElementException - if there is no such byte available.ByteIterator.next()public long skip(long byteCount)
ByteIteratorbyteCount.skip in interface ByteIteratorbyteCount - is the expected number of bytes to skip.byteCount.
However the value may be less if the end of this iterator has been reached before the according number of
bytes have been skipped. The value will always be greater or equal to 0.InputStream.skip(long)public long process(ByteProcessor processor, long byteCount)
ByteProcessablelength (as far as available) using the given
processor.process in interface ByteProcessableprocessor - is the ByteProcessor called to process the bytes. It may be called multiple types if the
data is sliced into multiple byte-arrays.byteCount - is the desired number of bytes to process. The value has to be greater or equal to 0. A value
of 0 will have no effect. If you want to process all available data to the end of stream or buffer
you may use Long.MAX_VALUE.length this will typically
be equal to length. However if the end of the data has been reached, a smaller value is returned.
The value will always be greater or equal to 0.protected void sync(AbstractByteArrayBufferBuffer master)
master.master - is the buffer this buffer was created from.protected boolean fill(InputStream inputStream) throws IOException
inputStream. If the buffer is already filled, this method
will have no effect and return false.inputStream - is the InputStream providing the data to fill this buffer with.true if the end of the stream was encountered while (re)filling this buffer, false
otherwise.IOException - if caused by the inputStream whilst reading.public int fill(byte[] buffer,
int offset,
int length)
ComposedByteBufferbuffer 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.fill in interface ComposedByteBufferbuffer - 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.buffer. Will be positive and less or
equal to the given length. Should be only less than maxLength if NOT enough
bytes are available.public ByteArray getByteArray(int index)
ComposedByteBufferByteArray 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.
ByteIterator.next() or ByteIterator.skip(long) will invalidate the returned ByteArray.
Please do NOT call these methods while working with ByteArrays.getByteArray in interface ComposedByteBufferindex - is the index of the requested ByteArray. It has to be in the range from 0 to
ComposedByteBuffer.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().ByteArray.ComposedByteBuffer.getByteArrayCount()public int getByteArrayCount()
ComposedByteBufferByteArrays currently available via ComposedByteBuffer.getByteArray(int). ByteIterator.next() or ByteIterator.skip(long) will invalidate the returned ByteArray.
Please do NOT call these methods while working with ByteArrays.getByteArrayCount in interface ComposedByteBufferByteArrays.Copyright © 2001–2016 mmm-Team. All rights reserved.