public abstract class ByteArrayView extends Object implements Serializable, Comparable<ByteArrayView>, Cloneable, com.streambase.sb.internal.CloneableData
ByteArrayView.copyBytes()
, and create a new ByteArrayView with ByteArrayView.makeView(byte[])
and return it when needed.
Note: Serializations of instances of this class that are created (e.g., by using
ObjectOutputStream
) in one version of StreamBase in general will not be
deserializable in any other version of StreamBase.Constructor and Description |
---|
ByteArrayView() |
Modifier and Type | Method and Description |
---|---|
abstract byte[] |
array()
Returns a reference to the backing array for this view.
|
String |
asString() |
ByteArrayView |
clone()
Implement Object.clone, which just delegates to ByteArrayView.copy().
|
int |
compareTo(ByteArrayView rhs)
compare this ByteArrayView to another lexigraphically
NB: no data is copied when doing this
|
abstract ByteArrayView |
copy()
Create a new ByteArrayView which wraps a new byte[] containing a copy of
this view's data
NB: this method copies the underlying data
|
abstract ByteArrayView |
copy(int offset,
int length)
Create a new ByteArrayView which wraps a new byte[] containing a copy of
this view's data
NB: this method copies the underlying data
|
abstract byte[] |
copyBytes()
Create a new byte[] containing a copy of this view's data.
|
abstract byte[] |
copyBytes(int offset,
int length)
Create a new byte[] containing a copy of this view's data within the provided window.
|
boolean |
equals(Object obj)
check if two ByteArrayViews are byte-for-byte identical
NB: this may devolve to a byte by byte comparison
|
byte |
get(int pos) |
int |
hashCode() |
abstract int |
length()
return the length of this view
NB: no data is copied when doing this
|
static ByteArrayView |
makeCopiedView(byte[] bytes)
Create a new ByteArrayView which wraps the entire provided byte[] (which is copied)
NB: The bytes are copied
|
static ByteArrayView |
makeCopiedView(byte[] bytes,
int offset,
int length)
Create a new ByteArrayView which wraps the provided byte[] (which is copied)
between offset and length from offset
NB: The bytes are copied
|
static ByteArrayView |
makeView(byte[] bytes)
Create a new ByteArrayView which wraps the entire provided byte[]
NB: no data is copied when doing this
|
static ByteArrayView |
makeView(byte[] bytes,
int offset,
int length)
Create a new ByteArrayView which wraps the provided byte[] between offset and length from offset
NB: no data is copied when doing this
|
static ByteArrayView |
makeView(String s)
Create a new ByteArrayView which converts the provided string to bytes and wraps it.
|
abstract int |
offset()
return the offset into the backing array of this view
NB: no data is copied when doing this
|
abstract ByteArrayView |
slice(int offset,
int length)
Create a new ByteArrayView which wraps a portion of this one
NB: no data is copied when doing this
|
String |
toString()
Formats a ByteArrayView by printing out every byte as a char.
|
abstract ByteBuffer |
view()
Create a new ByteBuffer which wraps all of this one
NB: no data is copied when doing this
|
abstract ByteBuffer |
view(int offset,
int length)
Create a new ByteBuffer which wraps a portion of this one
NB: no data is copied when doing this
|
public static ByteArrayView makeView(byte[] bytes)
bytes
- the data to be viewedpublic static ByteArrayView makeView(byte[] bytes, int offset, int length)
bytes
- the data to be viewedoffset
- the initial offset of the windowlength
- the length of the windowIllegalArgumentException
- if offset or length are negativeIndexOutOfBoundsException
- if offset+length > bytes.lengthpublic static ByteArrayView makeCopiedView(byte[] bytes)
bytes
- the data to be copied and viewedpublic static ByteArrayView makeCopiedView(byte[] bytes, int offset, int length)
bytes
- the data to be copied and viewedoffset
- the initial offset of the windowlength
- the length of the windowIllegalArgumentException
- if offset or length are negativeIndexOutOfBoundsException
- if offset+length > bytes.lengthpublic static ByteArrayView makeView(String s)
s
- the String to be viewedpublic abstract ByteArrayView slice(int offset, int length)
offset
- the initial offset of the window (relative to the current window)length
- the length of the windowIllegalArgumentException
- if offset or length are negativeIndexOutOfBoundsException
- if offset+length > length()public abstract ByteBuffer view(int offset, int length)
offset
- the initial offset of the window (relative to the current window)length
- the length of the windowIllegalArgumentException
- if offset or length are negativeIndexOutOfBoundsException
- if offset+length > length()public abstract ByteBuffer view()
public abstract byte[] array()
ByteArrayView.offset()
and offset() + ByteArrayView.length()
.
NB: no data is copied when doing thispublic abstract int offset()
public abstract int length()
public abstract ByteArrayView copy(int offset, int length)
offset
- the initial offset of the window (relative to the current window)length
- the length of the windowIllegalArgumentException
- if offset or length are negativeIndexOutOfBoundsException
- if offset+length > length()if you need a copy of the data in a byte[] indexed from 0 rather than offset()
public abstract ByteArrayView copy()
if you need a copy of the data in a byte[] indexed from 0 rather than offset()
public ByteArrayView clone()
public abstract byte[] copyBytes(int offset, int length)
ByteArrayView.array()
.
NB: this method copies the underlying dataoffset
- the initial offset of the window (relative to the current window)length
- the length of the windowIllegalArgumentException
- if offset or length are negativeIndexOutOfBoundsException
- if offset+length > length()public abstract byte[] copyBytes()
ByteArrayView.array()
.
NB: this method copies the underlying datapublic int compareTo(ByteArrayView rhs)
compareTo
in interface Comparable<ByteArrayView>
rhs
- The right hand side of this comparisonpublic boolean equals(Object obj)
public byte get(int pos)
public String toString()
public final String asString()