public class ByteArrayTools extends Object
| Constructor and Description |
|---|
ByteArrayTools() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
concat(byte[]... arrays)
Concatenate the byte array arguments.
|
static byte[] |
copy(byte[] bytes)
Make a copy of
bytes. |
static byte[] |
copy(byte[] bytes,
int offset,
int length)
Copy
length bytes from bytes starting at
from. |
static byte[] |
createBytes(int length,
byte val)
A byte array with the defined length, filled with val.
|
static byte[] |
createBytes(Object value)
Basic byte[] conversion.
|
static byte[] |
createRandomBytes(int length)
A random byte sequence of length
length. |
static boolean |
equals(byte[] array1,
int offset1,
byte[] array2,
int offset2,
int length)
Checks two arrays or sections thereof for equality.
|
static int |
indexOf(byte[] source,
int sourceOffset,
int sourceLen,
byte[] pattern,
int patternOffset,
int patternLen,
int fromIndex)
Search index of pattern in source.
|
static boolean |
startsWith(byte[] bytes,
byte[] pattern)
true if bytes starts with the byte sequence
defined in pattern. |
static void |
toBigEndianArray(byte[] bytes,
int offset,
int value,
int size)
Write value into bytes, starting at offset, most significant byte first,
using size bytes
|
static byte[] |
toBigEndianArray(int value,
int size)
Create bytes from value, most significant byte first, using size bytes
|
static int |
toBigEndianInt(byte[] buffer,
int offset,
int size)
Create a signed int from buffer, starting at offset and using size bytes,
most significant byte first.
|
static int |
toBigEndianIntUnsigned(byte[] buffer,
int offset,
int size)
Create an unsigned int from buffer, starting at offset and using size
bytes, most significant byte first.
|
static long |
toBigEndianLong(byte[] buffer,
int offset,
int size)
Create a signed long from buffer, starting at offset and using size
bytes, most significant byte first.
|
static long |
toBigEndianLongUnsigned(byte[] buffer,
int offset,
int size)
Create an unsigned long from buffer, starting at offset and using size
bytes, most significant byte first.
|
static byte[] |
toByteArray(BigInteger r)
Return r as an byte array without leading zero bytes.
|
static void |
toLittleEndianArray(byte[] bytes,
int offset,
int value,
int size)
Write value into bytes, starting at offset, least significant byte first,
using size bytes
|
static void |
toLittleEndianArray(byte[] bytes,
int offset,
long value,
int size)
Write value into bytes, starting at offset, least significant byte first,
using size bytes
|
static byte[] |
toLittleEndianArray(int value,
int size)
Create byte array from value, least significant byte first, using size
bytes
|
static byte[] |
toLittleEndianArray(long value,
int size)
Create byte array from value, least significant byte first, using size
bytes
|
static int |
toLittleEndianInt(byte[] buffer,
int offset,
int size)
Create a signed int from buffer, starting at offset and using size bytes,
least significant byte first.
|
static int |
toLittleEndianIntUnsigned(byte[] buffer,
int offset,
int size)
Create an unsigned int from buffer, starting at offset and using size
bytes, least significant byte first.
|
static long |
toLittleEndianLong(byte[] buffer,
int offset,
int size)
Create a signed long from buffer, starting at offset and using size
bytes, least significant byte first.
|
static long |
toLittleEndianLongUnsigned(byte[] buffer,
int offset,
int size)
Create an unsigned long from buffer, starting at offset and using size
bytes, least significant byte first.
|
public static byte[] concat(byte[]... arrays)
array - public static byte[] copy(byte[] bytes)
bytes.bytes - byte[] to be copiedbytespublic static byte[] copy(byte[] bytes,
int offset,
int length)
length bytes from bytes starting at
from.bytes - byte[] to be copiedoffset - starting position to copy fromlength - number of bytesbytespublic static byte[] createBytes(int length,
byte val)
length - val - public static byte[] createBytes(Object value) throws IOException
value - IOExceptionpublic static byte[] createRandomBytes(int length)
length.length - length.public static boolean equals(byte[] array1,
int offset1,
byte[] array2,
int offset2,
int length)
null or it's section is shorter than the compared length,
false is returned.array1 - offset1 - array2 - offset2 - length - must have a value greater than 0. A value of 0 always returns
false.true, if the compared array sections matchpublic static int indexOf(byte[] source,
int sourceOffset,
int sourceLen,
byte[] pattern,
int patternOffset,
int patternLen,
int fromIndex)
source - sourceOffset - sourceLen - pattern - patternOffset - patternLen - fromIndex - public static boolean startsWith(byte[] bytes,
byte[] pattern)
true if bytes starts with the byte sequence
defined in pattern.bytes - pattern - true if bytes starts with the byte
sequence defined in pattern.public static void toBigEndianArray(byte[] bytes,
int offset,
int value,
int size)
bytes - offset - value - size - public static byte[] toBigEndianArray(int value,
int size)
bytes - offset - value - size - public static int toBigEndianInt(byte[] buffer,
int offset,
int size)
buffer - offset - size - public static int toBigEndianIntUnsigned(byte[] buffer,
int offset,
int size)
buffer - offset - size - public static long toBigEndianLong(byte[] buffer,
int offset,
int size)
buffer - offset - size - public static long toBigEndianLongUnsigned(byte[] buffer,
int offset,
int size)
buffer - offset - size - public static byte[] toByteArray(BigInteger r)
r - public static void toLittleEndianArray(byte[] bytes,
int offset,
int value,
int size)
bytes - offset - value - size - public static void toLittleEndianArray(byte[] bytes,
int offset,
long value,
int size)
bytes - offset - value - size - public static byte[] toLittleEndianArray(int value,
int size)
value - size - public static byte[] toLittleEndianArray(long value,
int size)
value - size - public static int toLittleEndianInt(byte[] buffer,
int offset,
int size)
buffer - offset - size - public static int toLittleEndianIntUnsigned(byte[] buffer,
int offset,
int size)
This implementation does not check against integer overflow
buffer - offset - size - public static long toLittleEndianLong(byte[] buffer,
int offset,
int size)
buffer - offset - size - public static long toLittleEndianLongUnsigned(byte[] buffer,
int offset,
int size)
This implementation does not check against integer overflow
buffer - offset - size - Copyright © 2013 intarsys consulting GmbH. All Rights Reserved.