public final class ByteArrays extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BYTE_SIZE_IN_BITS |
static int |
BYTE_SIZE_IN_BYTES |
static int |
INET4_ADDRESS_SIZE_IN_BYTES |
static int |
INET6_ADDRESS_SIZE_IN_BYTES |
static int |
INT_SIZE_IN_BYTES |
static int |
LONG_SIZE_IN_BYTES |
static int |
SHORT_SIZE_IN_BYTES |
Modifier and Type | Method and Description |
---|---|
static short |
calcChecksum(byte[] data)
A utility method to calculate the Internet checksum.
|
static byte[] |
clone(byte[] array) |
static byte[] |
concatenate(byte[] arr1,
byte[] arr2) |
static byte |
getByte(byte[] array,
int offset) |
static Inet4Address |
getInet4Address(byte[] array,
int offset) |
static Inet4Address |
getInet4Address(byte[] array,
int offset,
ByteOrder bo) |
static Inet6Address |
getInet6Address(byte[] array,
int offset) |
static Inet6Address |
getInet6Address(byte[] array,
int offset,
ByteOrder bo) |
static int |
getInt(byte[] array,
int offset) |
static int |
getInt(byte[] array,
int offset,
ByteOrder bo) |
static int |
getInt(byte[] array,
int offset,
int length) |
static int |
getInt(byte[] array,
int offset,
int length,
ByteOrder bo) |
static LinkLayerAddress |
getLinkLayerAddress(byte[] array,
int offset,
int length) |
static LinkLayerAddress |
getLinkLayerAddress(byte[] array,
int offset,
int length,
ByteOrder bo) |
static long |
getLong(byte[] array,
int offset) |
static long |
getLong(byte[] array,
int offset,
ByteOrder bo) |
static MacAddress |
getMacAddress(byte[] array,
int offset) |
static MacAddress |
getMacAddress(byte[] array,
int offset,
ByteOrder bo) |
static short |
getShort(byte[] array,
int offset) |
static short |
getShort(byte[] array,
int offset,
ByteOrder bo) |
static byte[] |
getSubArray(byte[] array,
int offset) |
static byte[] |
getSubArray(byte[] array,
int offset,
int length) |
static byte[] |
parseByteArray(String hexString,
String separator) |
static byte[] |
reverse(byte[] array) |
static byte[] |
toByteArray(byte value) |
static byte[] |
toByteArray(InetAddress value) |
static byte[] |
toByteArray(InetAddress value,
ByteOrder bo) |
static byte[] |
toByteArray(int value) |
static byte[] |
toByteArray(int value,
ByteOrder bo) |
static byte[] |
toByteArray(int value,
int length) |
static byte[] |
toByteArray(int value,
int length,
ByteOrder bo) |
static byte[] |
toByteArray(LinkLayerAddress value) |
static byte[] |
toByteArray(LinkLayerAddress value,
ByteOrder bo) |
static byte[] |
toByteArray(long value) |
static byte[] |
toByteArray(long value,
ByteOrder bo) |
static byte[] |
toByteArray(MacAddress value) |
static byte[] |
toByteArray(MacAddress value,
ByteOrder bo) |
static byte[] |
toByteArray(short value) |
static byte[] |
toByteArray(short value,
ByteOrder bo) |
static String |
toHexString(byte[] array,
String separator) |
static String |
toHexString(byte[] array,
String separator,
int offset,
int length) |
static String |
toHexString(byte value,
String separator) |
static String |
toHexString(int value,
String separator) |
static String |
toHexString(int value,
String separator,
ByteOrder bo) |
static String |
toHexString(long value,
String separator) |
static String |
toHexString(long value,
String separator,
ByteOrder bo) |
static String |
toHexString(short value,
String separator) |
static String |
toHexString(short value,
String separator,
ByteOrder bo) |
static void |
validateBounds(byte[] arr,
int offset,
int len)
A utility method to validate arguments which indicate a part of an array.
|
static byte[] |
xor(byte[] arr1,
byte[] arr2) |
public static final int BYTE_SIZE_IN_BYTES
public static final int SHORT_SIZE_IN_BYTES
public static final int INT_SIZE_IN_BYTES
public static final int LONG_SIZE_IN_BYTES
public static final int INET4_ADDRESS_SIZE_IN_BYTES
public static final int INET6_ADDRESS_SIZE_IN_BYTES
public static final int BYTE_SIZE_IN_BITS
public static byte[] reverse(byte[] array)
array
- arraypublic static byte getByte(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static byte[] toByteArray(byte value)
value
- valuepublic static String toHexString(byte value, String separator)
value
- valueseparator
- separatorpublic static short getShort(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static short getShort(byte[] array, int offset, ByteOrder bo)
array
- arrayoffset
- offsetbo
- bopublic static byte[] toByteArray(short value)
value
- valuepublic static byte[] toByteArray(short value, ByteOrder bo)
value
- valuebo
- bopublic static String toHexString(short value, String separator)
value
- valueseparator
- separatorpublic static String toHexString(short value, String separator, ByteOrder bo)
value
- valueseparator
- separatorbo
- bopublic static int getInt(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static int getInt(byte[] array, int offset, ByteOrder bo)
array
- arrayoffset
- offsetbo
- bopublic static int getInt(byte[] array, int offset, int length)
array
- arrayoffset
- offsetlength
- lengthpublic static int getInt(byte[] array, int offset, int length, ByteOrder bo)
array
- arrayoffset
- offsetlength
- lengthbo
- bopublic static byte[] toByteArray(int value)
value
- valuepublic static byte[] toByteArray(int value, ByteOrder bo)
value
- valuebo
- bopublic static byte[] toByteArray(int value, int length)
value
- valuelength
- lengthpublic static byte[] toByteArray(int value, int length, ByteOrder bo)
value
- valuelength
- lengthbo
- bopublic static String toHexString(int value, String separator)
value
- valueseparator
- separatorpublic static String toHexString(int value, String separator, ByteOrder bo)
value
- valueseparator
- separatorbo
- bopublic static long getLong(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static long getLong(byte[] array, int offset, ByteOrder bo)
array
- arrayoffset
- offsetbo
- bopublic static byte[] toByteArray(long value)
value
- valuepublic static byte[] toByteArray(long value, ByteOrder bo)
value
- valuebo
- bopublic static String toHexString(long value, String separator)
value
- valueseparator
- separatorpublic static String toHexString(long value, String separator, ByteOrder bo)
value
- valueseparator
- separatorbo
- bopublic static MacAddress getMacAddress(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static MacAddress getMacAddress(byte[] array, int offset, ByteOrder bo)
array
- arrayoffset
- offsetbo
- bopublic static byte[] toByteArray(MacAddress value)
value
- valuepublic static byte[] toByteArray(MacAddress value, ByteOrder bo)
value
- valuebo
- bopublic static LinkLayerAddress getLinkLayerAddress(byte[] array, int offset, int length)
array
- arrayoffset
- offsetlength
- lengthpublic static LinkLayerAddress getLinkLayerAddress(byte[] array, int offset, int length, ByteOrder bo)
array
- arrayoffset
- offsetlength
- lengthbo
- bopublic static byte[] toByteArray(LinkLayerAddress value)
value
- valuepublic static byte[] toByteArray(LinkLayerAddress value, ByteOrder bo)
value
- valuebo
- bopublic static Inet4Address getInet4Address(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static Inet4Address getInet4Address(byte[] array, int offset, ByteOrder bo)
array
- arrayoffset
- offsetbo
- bopublic static Inet6Address getInet6Address(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static Inet6Address getInet6Address(byte[] array, int offset, ByteOrder bo)
array
- arrayoffset
- offsetbo
- bopublic static byte[] toByteArray(InetAddress value)
value
- valuepublic static byte[] toByteArray(InetAddress value, ByteOrder bo)
value
- valuebo
- bopublic static byte[] getSubArray(byte[] array, int offset, int length)
array
- arrayoffset
- offsetlength
- lengthpublic static byte[] getSubArray(byte[] array, int offset)
array
- arrayoffset
- offsetpublic static String toHexString(byte[] array, String separator)
array
- arrayseparator
- separatorpublic static String toHexString(byte[] array, String separator, int offset, int length)
array
- arrayseparator
- separatoroffset
- offsetlength
- lengthpublic static short calcChecksum(byte[] data)
data
- datapublic static byte[] parseByteArray(String hexString, String separator)
hexString
- hexStringseparator
- separatorpublic static byte[] clone(byte[] array)
array
- arraypublic static void validateBounds(byte[] arr, int offset, int len)
arr
- arroffset
- offsetlen
- lenNullPointerException
- if the arr
is null.IllegalArgumentException
- if arr
is empty or len
is zero.ArrayIndexOutOfBoundsException
- if offset
or len
is negative,
or (offset
+ len
) is greater than or equal to arr.length
.public static byte[] xor(byte[] arr1, byte[] arr2)
arr1
- arr1arr2
- arr2public static byte[] concatenate(byte[] arr1, byte[] arr2)
arr1
- arr1arr2
- arr2Copyright © 2011–2016 Pcap4J.org. All rights reserved.