public abstract class ByteArrayView extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<ByteArrayView>, java.lang.Cloneable, com.streambase.sb.internal.CloneableData
ByteArrayView provides an immutable window onto a byte[] or a part of one, specified with an offset and length. It provides convenience routines to create new windows on the current view as either ByteArrayViews or ByteBuffers.
Only the copy() methods copy the underlying data, so changes in the parent byte[] will be reflected in the view's results
Note: The ByteArrayView and its underlying Blob object should not be modified in-place
by a StreamBase application. Modifying a Blob may introduce race conditions. If you do need to
modify a Blob's data, create a new Blob or ByteArrayView object to receive the result. Use
copy methods such as 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.
|
java.lang.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(java.lang.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(java.lang.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
|
java.lang.String |
toString()
Formats a ByteArrayView by printing out every byte as a char.
|
abstract java.nio.ByteBuffer |
view()
Create a new ByteBuffer which wraps all of this one
NB: no data is copied when doing this
|
abstract java.nio.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 windowjava.lang.IllegalArgumentException
- if offset or length are negativejava.lang.IndexOutOfBoundsException
- 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 windowjava.lang.IllegalArgumentException
- if offset or length are negativejava.lang.IndexOutOfBoundsException
- if offset+length > bytes.lengthpublic static ByteArrayView makeView(java.lang.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 windowjava.lang.IllegalArgumentException
- if offset or length are negativejava.lang.IndexOutOfBoundsException
- if offset+length > length()public abstract java.nio.ByteBuffer view(int offset, int length)
offset
- the initial offset of the window (relative to the current window)length
- the length of the windowjava.lang.IllegalArgumentException
- if offset or length are negativejava.lang.IndexOutOfBoundsException
- if offset+length > length()public abstract java.nio.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 windowjava.lang.IllegalArgumentException
- if offset or length are negativejava.lang.IndexOutOfBoundsException
- 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()
clone
in interface com.streambase.sb.internal.CloneableData
clone
in class java.lang.Object
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 windowjava.lang.IllegalArgumentException
- if offset or length are negativejava.lang.IndexOutOfBoundsException
- if offset+length > length()public abstract byte[] copyBytes()
ByteArrayView.array()
.
NB: this method copies the underlying datapublic int compareTo(ByteArrayView rhs)
compareTo
in interface java.lang.Comparable<ByteArrayView>
rhs
- The right hand side of this comparisonpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The right hand side of this comparisonpublic int hashCode()
hashCode
in class java.lang.Object
public byte get(int pos)
public java.lang.String toString()
toString
in class java.lang.Object
public final java.lang.String asString()