Class ByteArray
java.lang.Object
com.android.dx.util.ByteArray
Wrapper for a
byte[], which provides read-only access and
can "reveal" a partial slice of the underlying array.
Note: Multibyte accessors all use big-endian order.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHelper interface that allows one to get the cursor (of a stream).static classHelper class formakeDataInputStream().classHelper class formakeInputStream(), which implements the stream functionality. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetByte(int off) Gets thesigned bytevalue at a particular offset.voidgetBytes(byte[] out, int offset) Copies the contents of this instance into the given rawbyte[]at the given offset.intgetInt(int off) Gets thesigned intvalue at a particular offset.longgetLong(int off) Gets thesigned longvalue at a particular offset.intgetShort(int off) Gets thesigned shortvalue at a particular offset.intgetUnsignedByte(int off) Gets theunsigned bytevalue at a particular offset.intgetUnsignedShort(int off) Gets theunsigned shortvalue at a particular offset.Gets aDataInputStreamthat reads from this instance, with the cursor starting at the beginning of this instance's data.Gets aInputStreamthat reads from this instance, with the cursor starting at the beginning of this instance's data.intsize()Gets the size of the array, in bytes.slice(int start, int end) Returns a slice (that is, a sub-array) of this instance.intunderlyingOffset(int offset) Returns the offset into the given array represented by the given offset into this instance.
-
Constructor Details
-
ByteArray
public ByteArray(byte[] bytes, int start, int end) Constructs an instance.- Parameters:
bytes-non-null;the underlying arraystart->= 0;start index of the slice (inclusive)end->= start, <= bytes.length;end index of the slice (exclusive)
-
ByteArray
public ByteArray(byte[] bytes) Constructs an instance from an entirebyte[].- Parameters:
bytes-non-null;the underlying array
-
-
Method Details
-
size
public int size()Gets the size of the array, in bytes.- Returns:
>= 0;the size
-
slice
Returns a slice (that is, a sub-array) of this instance.- Parameters:
start->= 0;start index of the slice (inclusive)end->= start, <= size();end index of the slice (exclusive)- Returns:
non-null;the slice
-
underlyingOffset
public int underlyingOffset(int offset) Returns the offset into the given array represented by the given offset into this instance.- Parameters:
offset- offset into this instance- Returns:
- corresponding offset into
bytes - Throws:
IllegalArgumentException- thrown ifbytesis not the underlying array of this instance
-
getByte
public int getByte(int off) Gets thesigned bytevalue at a particular offset.- Parameters:
off->= 0, < size();offset to fetch- Returns:
signed byteat that offset
-
getShort
public int getShort(int off) Gets thesigned shortvalue at a particular offset.- Parameters:
off->= 0, < (size() - 1);offset to fetch- Returns:
signed shortat that offset
-
getInt
public int getInt(int off) Gets thesigned intvalue at a particular offset.- Parameters:
off->= 0, < (size() - 3);offset to fetch- Returns:
signed intat that offset
-
getLong
public long getLong(int off) Gets thesigned longvalue at a particular offset.- Parameters:
off->= 0, < (size() - 7);offset to fetch- Returns:
signed intat that offset
-
getUnsignedByte
public int getUnsignedByte(int off) Gets theunsigned bytevalue at a particular offset.- Parameters:
off->= 0, < size();offset to fetch- Returns:
unsigned byteat that offset
-
getUnsignedShort
public int getUnsignedShort(int off) Gets theunsigned shortvalue at a particular offset.- Parameters:
off->= 0, < (size() - 1);offset to fetch- Returns:
unsigned shortat that offset
-
getBytes
public void getBytes(byte[] out, int offset) Copies the contents of this instance into the given rawbyte[]at the given offset. The given array must be large enough.- Parameters:
out-non-null;array to hold the outputoffset-non-null;index intooutfor the first byte of output
-
makeDataInputStream
Gets aDataInputStreamthat reads from this instance, with the cursor starting at the beginning of this instance's data. Note: The returned instance may be cast toByteArray.GetCursorif needed.- Returns:
non-null;an appropriately-constructedDataInputStreaminstance
-
makeInputStream
Gets aInputStreamthat reads from this instance, with the cursor starting at the beginning of this instance's data. Note: The returned instance may be cast toByteArray.GetCursorif needed.- Returns:
non-null;an appropriately-constructedInputStreaminstancex
-