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, toString
checkSubArray, getBytesAvailable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getBytes, getBytesAvailable, getMaximumIndex, getMinimumIndex
private int currentIndex
getCurrentIndex()
public 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()
getCurrentIndex
in interface ByteArray
getCurrentIndex
in class ByteArrayImpl
byte array
.public void setCurrentIndex(int currentIndex)
currentIndex
. This can be useful e.g. if data from the
buffer
has been consumed externally. setCurrentIndex
in interface ByteArrayBuffer
currentIndex
- 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)
maximumIndex
. This may be useful if the buffer should be
reused. setMaximumIndex
in class ByteArrayImpl
maximumIndex
- 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
ByteIterator
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 ByteIterator
NoSuchElementException
- if there is no such byte available
.Iterator.next()
public byte peek() throws NoSuchElementException
ByteIterator.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 ByteIterator
NoSuchElementException
- if there is no such byte available
.ByteIterator.next()
public boolean hasNext()
next byte
available.hasNext
in interface ByteIterator
true
if there is a next byte
available, false
otherwise
(if the end of this buffer has been reached).public long skip(long byteCount)
byteCount
.skip
in interface ByteIterator
byteCount
- 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)
ByteArray
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 ByteArray
createSubArray
in class ByteArrayImpl
minimum
- 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–2014 mmm-Team. All rights reserved.