public class ByteArrayImpl extends AbstractByteArray
ByteBuffer
but a lot simpler.ByteBuffer.wrap(byte[], int, int)
Modifier and Type | Field and Description |
---|---|
private byte[] |
buffer |
private int |
maximumIndex |
private int |
minimumIndex |
Constructor and Description |
---|
ByteArrayImpl(byte[] buffer)
The constructor.
|
ByteArrayImpl(byte[] buffer,
int startIndex,
int maximumIndex)
The constructor.
|
ByteArrayImpl(int capacity)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
ByteArrayImpl |
createSubArray(int minimum,
int maximum)
This method creates a new
ByteArray with the same bytes but the given
indices.ATTENTION: If the implementation is immutable and the given 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. |
byte[] |
getBytes()
This method gets the underlying byte-array of this buffer.
|
int |
getCurrentIndex()
This method gets the offset in the
byte array . |
int |
getMaximumIndex()
This method gets the maximum index in the
buffer . |
int |
getMinimumIndex()
This method gets the minimum index where to start reading in the
byte array . |
protected void |
setMaximumIndex(int maximumIndex)
This method sets the
maximumIndex . |
String |
toString() |
checkSubArray, getBytesAvailable
private final byte[] buffer
getBytes()
private int minimumIndex
getMinimumIndex()
private int maximumIndex
getMaximumIndex()
public ByteArrayImpl(int capacity)
capacity
- is the length
of the internal buffer
.public ByteArrayImpl(byte[] buffer)
buffer
- is the internal buffer
.public ByteArrayImpl(byte[] buffer, int startIndex, int maximumIndex)
buffer
- is the internal buffer
.startIndex
- is the current index
as well as the
minimum index
.maximumIndex
- is the maximum index
.public byte[] getBytes()
minimumIndex
(typically currentIndex
to
maximumIndex
. Only the creator of this object may modify this array.ByteArray.getCurrentIndex()
,
ByteArray.getMaximumIndex()
public int getCurrentIndex()
byte array
.public int getMinimumIndex()
byte array
. It will
be in the range from 0
to maximumIndex
+ 1
. This is
typically the same as the current index
. However a
mutable variant
of a ByteArray
may allow to modify
(increase) the current-index
. The value returned by this method can NOT be
modified.public int getMaximumIndex()
buffer
. It will be in the range from
-1
to ByteArray.getBytes()
.length - 1
.-1
) indicates that the buffer
does NOT contain data
(payload).protected void setMaximumIndex(int maximumIndex)
maximumIndex
. This may be useful if the buffer should be
reused.maximumIndex
- is the maximumIndex
to set. It has to be in the range from
0
( currentIndex
- 1
) to
getBytes()
.length
.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 AbstractByteArray
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-2013 mmm-Team. All Rights Reserved.