|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdanger.util.ByteArray
public final class ByteArray
Utilities for accessing instances of byte[]. Note: Many of
these methods are performed in native code on a device.
| Field Summary | |
|---|---|
static char |
UNICODE_REPLACEMENT_CHARACTER
standard Unicode replacement character for bogus data |
| Method Summary | |
|---|---|
static int |
compareTo(byte[] bytesA,
int offsetA,
int lenA,
byte[] bytesB,
int offsetB,
int lenB)
Compare two ranges of bytes in arrays, returning one of {-1,
0, 1} to indicate whether (respectively) the first is "less
than," "equal to," or "greater than" the second. |
static boolean |
contains(byte[] bytes,
int offset,
int len,
byte[] key)
|
static boolean |
containsIgnoreCase(byte[] bytes,
int offset,
int len,
byte[] key)
Determine whether a given section of one byte[]
contains bytes equal to the full contents of another
byte[], when considering the two arrays to be UTF-8
encoded character data and disregarding case when doing comparisons. |
static int |
decodeUtf8Char(byte[] bytes,
int index,
int maxIndex)
Decode a UTF-8 character from the given byte array at the given index, but not using bytes at or beyond the given maximum index. |
static boolean |
endsWith(byte[] haystack,
int hlen,
byte[] needle,
int nlen)
|
static boolean |
equals(byte[] bytesA,
byte[] bytesB)
Compare two instances of byte[] for equality. |
static byte[] |
fromStream(InputStream in)
Convert an InputStream to an array of bytes by reading the stream bytes until an EOF is encountered. |
static int |
indexOf(byte[] inBase,
int inOffset,
int inLength,
byte[] inKey)
Search for the first occurance of one byte[] within a span
of another. |
static int |
readInt(byte[] bytes,
int offset)
Read an int out of a byte[] at the given
offset, in little-endian form (that is, low-order byte first). |
static int |
readShort(byte[] bytes,
int offset)
Read a short out of a byte[] at the given
offset, in little-endian form (that is, low-order byte first). |
static boolean |
regionMatches(byte[] a,
int ax,
byte[] b,
int bx,
int len)
|
static boolean |
startsWith(byte[] bytes,
int offset,
int len,
byte[] key)
Determine whether a given section of one byte[] starts
with the full contents of another byte[]. |
static boolean |
startsWithIgnoreCase(byte[] bytes,
int offset,
int len,
byte[] key)
|
static void |
writeInt(byte[] bytes,
int offset,
int value)
Write an int to byte[] at the given
offset, in little-endian form (that is, low-order byte first). |
static void |
writeShort(byte[] bytes,
int offset,
int value)
Write a short to byte[] at the given
offset, in little-endian form (that is, low-order byte first). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final char UNICODE_REPLACEMENT_CHARACTER
| Method Detail |
|---|
public static byte[] fromStream(InputStream in)
throws IOException
in - the stream to read the bytes from
IOException - thrown if there is a problem with the input stream or buffer
for building the byte array.
NullPointerException - thrown if in is
passed as null
public static int readInt(byte[] bytes,
int offset)
int out of a byte[] at the given
offset, in little-endian form (that is, low-order byte first).
bytes - non-null; the array to read fromoffset - the offset to start reading at
int
ArrayIndexOutOfBoundsException - thrown if offset
is out of range
NullPointerException - thrown of bytes is
passed as null
public static int readShort(byte[] bytes,
int offset)
short out of a byte[] at the given
offset, in little-endian form (that is, low-order byte first).
bytes - non-null; the array to read fromoffset - the offset to start reading at
short
ArrayIndexOutOfBoundsException - thrown if offset
is out of range
NullPointerException - thrown of bytes is
passed as null
public static void writeInt(byte[] bytes,
int offset,
int value)
int to byte[] at the given
offset, in little-endian form (that is, low-order byte first).
If the offset is out of range, then an exception is thrown and
the array is left unaltered.
bytes - non-null; the array to store intooffset - the offset to start storing atvalue - the value to store
ArrayIndexOutOfBoundsException - thrown if offset
is out of range
NullPointerException - thrown of bytes is
passed as null
public static void writeShort(byte[] bytes,
int offset,
int value)
short to byte[] at the given
offset, in little-endian form (that is, low-order byte first).
If the offset is out of range, then an exception is thrown and
the array is left unaltered.
bytes - non-null; the array to store intooffset - the offset to start storing atvalue - the value to store
ArrayIndexOutOfBoundsException - thrown if offset
is out of range
NullPointerException - thrown of bytes is
passed as null
public static int compareTo(byte[] bytesA,
int offsetA,
int lenA,
byte[] bytesB,
int offsetB,
int lenB)
{-1,
0, 1} to indicate whether (respectively) the first is "less
than," "equal to," or "greater than" the second. If one of the
arrays is passed as null, then it is considered to be
"less than" the other, unless the other one is also
null, in which case the two are considered equal.
Otherwise, corresponding bytes are compared, starting from early
offsets, up to the smaller of the two lengths passed. Whichever array
contains a byte that is smaller than the other is considered "less
than" the other. If all bytes compared are equal, then the range
with the smaller length is considered "less than" the other. If the
two lengths are the same, then the ranges are considered "equal."
bytesA - null-ok; an array to compareoffsetA - the offset to start at in bytesAlenA - the number of bytes in the range in bytesAbytesB - null-ok; another array to compareoffsetB - the offset to start at in bytesBlenB - the number of bytes in the range in bytesB
{-1, 0, 1} to indicate whether
(respectively) the first range is "less than," "equal to," or
"greater than" the second
ArrayIndexOutOfBoundsException - thrown if the arguments
end up demanding that an out-of-range element be accessed
public static boolean equals(byte[] bytesA,
byte[] bytesB)
byte[] for equality. They
are considered equal if either: both are null; both
are non-null, of the same length, and with equal
contents.
bytesA - null-ok; an array to comparebytesB - null-ok; an array to compare it to
true if and only if the two arrays are considered
"equal" to each other
public static boolean startsWith(byte[] bytes,
int offset,
int len,
byte[] key)
byte[] starts
with the full contents of another byte[].
bytes - null-ok; an array to compareoffset - the offset to start at in byteslen - the number of bytes in the range in byteskey - non-null; the array whose contents may or may not be
the initial bytes in the specified range in bytes
true iff the contents of key match
the first key.length bytes in the specified range; this
is notably false if len < key.length
NullPointerException - thrown if key == null
IllegalArgumentException - thrown if offset
and len don't specify an existing range within
bytes
public static boolean startsWithIgnoreCase(byte[] bytes,
int offset,
int len,
byte[] key)
public static boolean contains(byte[] bytes,
int offset,
int len,
byte[] key)
public static boolean containsIgnoreCase(byte[] bytes,
int offset,
int len,
byte[] key)
byte[]
contains bytes equal to the full contents of another
byte[], when considering the two arrays to be UTF-8
encoded character data and disregarding case when doing comparisons.
Per-character comparisons are done in the style of
String.equalsIgnoreCase() (as opposed to the subtly
different style in String.compareToIgnoreCase).
bytes - null-ok; an array to compareoffset - the offset to start at in byteslen - the number of bytes in the range in byteskey - non-null; the array whose contents may or may not be
equal, without regard to case, to a portion of the bytes in the
specified range in bytes
true iff an equivalent of the contents of
key are found inside bytes in the
specified range
NullPointerException - thrown if key == null or
bytes == null
IllegalArgumentException - thrown if offset
and len don't specify an existing range within
bytes
public static int decodeUtf8Char(byte[] bytes,
int index,
int maxIndex)
Note: This decodes in exactly the same way that String
decodes, including error cases.
bytes - non-null; bytes to decode fromindex - the start index for the charactermaxIndex - the limit of decoding (exclusive)
(bytesConsumed << 16) | decodedCharacter
NullPointerException - thrown if bytes == null
IndexOutOfBoundsException - thrown if index is
outside of the legal range for bytes or if
maxIndex is out of range and index points
at the start of a multibyte character that would overflow into
out-of-range territory
public static boolean regionMatches(byte[] a,
int ax,
byte[] b,
int bx,
int len)
public static boolean endsWith(byte[] haystack,
int hlen,
byte[] needle,
int nlen)
public static final int indexOf(byte[] inBase,
int inOffset,
int inLength,
byte[] inKey)
byte[] within a span
of another. Searching is done from inBase[inOffset] through
inBase[inOffset + inLength].
inBase - non-null; the array in which to searchinOffset - the beginning of the span within inBase to searchinLength - the length of the span within inBase to search
inKey
within inBase, or -1 if not found.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||