public class ByteArrayBufferImpl extends ByteArrayImpl implements ByteArrayBuffer
ByteBuffer but a lot simpler. However it allows to
set the current index so the internal buffer-array can be consumed
externally and proceeded very fast. ByteBuffer.wrap(byte[], int, int)| Modifier and Type | Field and Description |
|---|---|
private int |
currentIndex |
| Constructor and Description |
|---|
ByteArrayBufferImpl(byte[] buffer)
The constructor.
|
ByteArrayBufferImpl(byte[] buffer,
int currentIndex,
int maximumIndex)
The constructor.
|
ByteArrayBufferImpl(int capacity)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
ByteArrayImpl |
createSubArray(int minimum,
int maximum)
|
int |
getCurrentIndex()
This method gets the offset in the
byte array. |
boolean |
hasNext()
This method determines if there is a
next byte available. |
byte |
next()
This method gets the current byte in the iteration.
|
byte |
peek()
This method gets the current byte in the iteration.
|
void |
setCurrentIndex(int currentIndex)
This method sets the
currentIndex. |
void |
setMaximumIndex(int maximumIndex)
This method sets the
maximumIndex. |
long |
skip(long byteCount)
This method skips the number of bytes given by
byteCount. |
getBytes, getMaximumIndex, getMinimumIndex, toStringcheckSubArray, getBytesAvailableclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetBytes, getBytesAvailable, getMaximumIndex, getMinimumIndexpublic ByteArrayBufferImpl(int capacity)
capacity - is the length of the internal buffer.public ByteArrayBufferImpl(byte[] buffer)
buffer - is the internal buffer.public ByteArrayBufferImpl(byte[] buffer,
int currentIndex,
int maximumIndex)
buffer - is the internal buffer.currentIndex - is the current index.maximumIndex - is the maximum index.public int getCurrentIndex()
ByteArraygetCurrentIndex in interface ByteArraygetCurrentIndex in class ByteArrayImplbyte array.public void setCurrentIndex(int currentIndex)
ByteArrayBuffercurrentIndex. This can be useful e.g. if data from the
buffer has been consumed externally. setCurrentIndex in interface ByteArrayBuffercurrentIndex - is the currentIndex to set. It has to be in the range from
minimumIndex to maximumIndex + 1. A value
of maximumIndex + 1 indicates that the buffer is consumed.public void setMaximumIndex(int maximumIndex)
ByteArrayImplmaximumIndex. This may be useful if the buffer should be reused.
setMaximumIndex in class ByteArrayImplmaximumIndex - is the maximumIndex to set. It has to be in the range from 0
( currentIndex - 1) to ByteArrayImpl.getBytes().length.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 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 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 ByteArrayImpl createSubArray(int minimum, int maximum)
ByteArrayByteArray with the same bytes but the given indices. minimum and maximum index are both equal to the
current indices of this ByteArray this method may return the instance itself ( this) rather than
creating a new one.createSubArray in interface ByteArraycreateSubArray in class ByteArrayImplminimum - is the minimumIndex and the currentIndex for
the new ByteArray. It has to be greater or equal to the minimumIndex of
this ByteArray.maximum - is the maximumIndex for the new ByteArray.ByteArray with the given indices.Copyright © 2001–2016 mmm-Team. All rights reserved.