| Constructor and Description |
|---|
ByteArraySegment(byte[] array)
Creates a new instance of the ByteArraySegment class that wraps the entire given array.
|
ByteArraySegment(byte[] array,
int startOffset,
int length)
Creates a new instance of the ByteArraySegment class that wraps the given array range.
|
ByteArraySegment(byte[] array,
int startOffset,
int length,
boolean readOnly)
Creates a new instance of the ByteArraySegment class that wraps the given array range.
|
ByteArraySegment(java.nio.ByteBuffer buff)
Creates a new instance of the ByteArraySegment class that wraps an array backed ByteBuffer.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
Gets a reference to the backing array for this ArrayView.
|
int |
arrayOffset()
Gets a value indicating the offset in the backing array where this ArrayView starts at.
|
ByteArraySegment |
asReadOnly()
Returns a new ByteArraySegment that wraps the same underlying array that this ByteSegmentDoes, except that the
new instance is marked as Read-Only.
|
void |
copyFrom(ByteArraySegment source,
int targetOffset,
int length)
Copies a specified number of bytes from the given ByteArraySegment into this ByteArraySegment.
|
void |
copyTo(byte[] target,
int targetOffset,
int length)
Copies a specified number of bytes from this ArrayView into the given target array.
|
byte |
get(int index)
Gets the value at the specified index.
|
byte[] |
getCopy()
Returns a copy of the contents of this ArrayView.
|
int |
getLength()
Gets a value representing the length of this ArrayView.
|
java.io.InputStream |
getReader()
Creates an InputStream that can be used to read the contents of this ArrayView.
|
java.io.InputStream |
getReader(int offset,
int length)
Creates an InputStream that can be used to read the contents of this ArrayView.
|
java.io.OutputStream |
getWriter()
Creates an OutputStream that can be used to write contents to this ByteArraySegment.
|
boolean |
isReadOnly()
Gets a value indicating whether the ByteArraySegment is read-only.
|
int |
readFrom(java.io.InputStream stream)
Attempts to read the contents of the InputStream and load it into this ByteArraySegment.
|
void |
set(int index,
byte value)
Sets the value at the specified index.
|
ByteArraySegment |
subSegment(int offset,
int length)
Returns a new ByteArraySegment that is a sub-segment of this ByteArraySegment.
|
ByteArraySegment |
subSegment(int offset,
int length,
boolean readOnly)
Returns a new ByteArraySegment that is a sub-segment of this ByteArraySegment.
|
void |
writeTo(java.io.OutputStream stream)
Writes the entire contents of this ByteArraySegment to the given OutputStream.
|
public ByteArraySegment(byte[] array)
array - The array to wrap.java.lang.NullPointerException - If the array is null.public ByteArraySegment(byte[] array,
int startOffset,
int length)
array - The array to wrap.startOffset - The offset within the array to start the segment at.length - The length of the segment.java.lang.NullPointerException - If the array is null.java.lang.ArrayIndexOutOfBoundsException - If StartOffset or Length have invalid values.public ByteArraySegment(java.nio.ByteBuffer buff)
buff - The ByteBuffer to wrap.java.lang.NullPointerException - If the array is null.java.lang.UnsupportedOperationException - If buff is not backed by an array.public ByteArraySegment(byte[] array,
int startOffset,
int length,
boolean readOnly)
array - The array to wrap.startOffset - The offset within the array to start the segment at.length - The length of the segment.readOnly - If true, no modifications will be allowed on the segment.java.lang.NullPointerException - If the array is null.java.lang.ArrayIndexOutOfBoundsException - If StartOffset or Length have invalid values.public byte get(int index)
ArrayViewpublic int getLength()
ArrayViewpublic byte[] array()
ArrayViewpublic int arrayOffset()
ArrayViewarrayOffset in interface ArrayViewpublic java.io.InputStream getReader()
ArrayViewpublic java.io.InputStream getReader(int offset,
int length)
ArrayViewpublic byte[] getCopy()
ArrayViewpublic void copyTo(byte[] target,
int targetOffset,
int length)
ArrayViewpublic void set(int index,
byte value)
index - The index to set the value at.value - The value to set.java.lang.IllegalStateException - If the ByteArraySegment is readonly.java.lang.ArrayIndexOutOfBoundsException - If index is invalid.public boolean isReadOnly()
public void copyFrom(ByteArraySegment source, int targetOffset, int length)
source - The ByteArraySegment to copy bytes from.targetOffset - The offset within this ByteArraySegment to start copying at.length - The number of bytes to copy.java.lang.IllegalStateException - If the ByteArraySegment is readonly.java.lang.ArrayIndexOutOfBoundsException - If targetOffset or length are invalid.public void writeTo(java.io.OutputStream stream)
throws java.io.IOException
stream - The OutputStream to write to.java.io.IOException - If the OutputStream threw one.public int readFrom(java.io.InputStream stream)
throws java.io.IOException
Only attempts to read the data, and does not expect any other header/footer information in the InputStream. This method is the exact reverse of writeTo().
stream - The InputStream to read from.java.io.IOException - If the InputStream threw one.public java.io.OutputStream getWriter()
java.lang.IllegalStateException - If the ByteArraySegment is readonly.public ByteArraySegment subSegment(int offset, int length)
offset - The offset within this ByteArraySegment where the new ByteArraySegment starts.length - The length of the new ByteArraySegment.java.lang.ArrayIndexOutOfBoundsException - If offset or length are invalid.public ByteArraySegment subSegment(int offset, int length, boolean readOnly)
offset - The offset within this ByteArraySegment where the new ByteArraySegment starts.length - The length of the new ByteArraySegment.readOnly - Whether the resulting sub-segment should be read-only.
Note: if this ByteArraySegment is already read-only, this argument is ignored and the resulting
segment is read-onlyjava.lang.ArrayIndexOutOfBoundsException - If offset or length are invalid.public ByteArraySegment asReadOnly()