| Constructor and Description |
|---|
ByteUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
byteArrayToInt(byte[] byteArray)
Converts the given byte array (4 bytes length max) into an integer.
|
static long |
byteArrayToLong(byte[] byteArray)
Converts the given byte array (8 bytes length max) into a long.
|
static short |
byteArrayToShort(byte[] byteArray)
Converts the given byte array (2 bytes length max) to short.
|
static String |
byteArrayToString(byte[] value)
Converts the given byte array into a string.
|
static int |
byteToInt(byte b)
Converts the given byte into an integer.
|
static byte[] |
intToByteArray(int value)
Converts the given integer value into a byte array.
|
static boolean |
isBitEnabled(int containerInteger,
int bitPosition)
Returns whether the specified bit of the given integer is set to 1
or not.
|
static byte[] |
longToByteArray(long value)
Converts the given long value into a byte array.
|
static byte[] |
newByteArray(byte[] data,
int finalSize)
Generates a new byte array of the given size using the given data and
filling with ASCII zeros (0x48) the remaining space.
|
static boolean |
readBooleanFromByte(byte containerByte,
int bitOffset)
Reads a boolean value from the given byte at the given bit position.
|
static byte[] |
readBytes(int numBytes,
ByteArrayInputStream inputStream)
Reads the given amount of bytes from the given byte array input stream.
|
static int |
readIntegerFromByte(byte containerByte,
int bitOffset,
int bitLength)
Reads an integer value from the given byte using the given bit offset
and the given bit size.
|
static String |
readString(ByteArrayInputStream inputStream)
Reads a null-terminated string from the given byte array input stream.
|
static byte[] |
readUntilCR(ByteArrayInputStream inputStream)
Reads from the given byte array input stream until a CR character is
found or the end of stream is reached.
|
static byte[] |
shortToByteArray(short value)
Converts the given short value into a byte array.
|
static byte[] |
stringToByteArray(String value)
Converts the given string into a byte array.
|
static byte[] |
swapByteArray(byte[] source)
Swaps the given byte array order.
|
public ByteUtils()
public static int byteArrayToInt(byte[] byteArray)
byteArray - Byte array to convert to integer (4 bytes length max).NullPointerException - if byteArray == null.intToByteArray(int)public static long byteArrayToLong(byte[] byteArray)
byteArray - Byte array to convert to long (8 bytes length max).NullPointerException - if b == null.longToByteArray(long)public static short byteArrayToShort(byte[] byteArray)
byteArray - Byte array to convert to short (2 bytes length max).NullPointerException - if byteArray == null.shortToByteArray(short)public static String byteArrayToString(byte[] value)
value - Byte array to convert to string.NullPointerException - if value == null.public static int byteToInt(byte b)
b - Byte to convert to integer.public static byte[] intToByteArray(int value)
value - Integer value to convert to byte array.byteArrayToInt(byte[])public static boolean isBitEnabled(int containerInteger, int bitPosition)
containerInteger - Integer to check the given bit position
enablement state.bitPosition - Position of the bit to check its enablement state.true if the given bit position is set to 1
in the containerInteger, false otherwise.public static byte[] longToByteArray(long value)
value - Long value to convert to byte array.byteArrayToLong(byte[])public static byte[] newByteArray(byte[] data, int finalSize)
If new size is lower than current, array is truncated.
data - Data to use in the new array.finalSize - Final size of the array.NullPointerException - if data == null.public static boolean readBooleanFromByte(byte containerByte, int bitOffset)
containerByte - Byte to read boolean value from.bitOffset - Offset inside the byte to read the boolean value.public static byte[] readBytes(int numBytes, ByteArrayInputStream inputStream)
numBytes - Number of bytes to read.inputStream - Byte array input stream to read bytes from.IllegalArgumentException - if numBytes < 0.NullPointerException - if inputStream == null.readString(ByteArrayInputStream),
readUntilCR(ByteArrayInputStream)public static int readIntegerFromByte(byte containerByte, int bitOffset, int bitLength)
containerByte - Byte to read the integer from.bitOffset - Offset inside the byte to start reading integer value.bitLength - Size in bits of the integer value to read.public static String readString(ByteArrayInputStream inputStream)
inputStream - Byte array input stream to read string from.ByteArrayInputStream.NullPointerException - if inputStream == null.readBytes(int, ByteArrayInputStream),
readUntilCR(ByteArrayInputStream)public static byte[] readUntilCR(ByteArrayInputStream inputStream)
inputStream - Byte array input stream to read from.NullPointerException - if inputStream == null.readBytes(int, ByteArrayInputStream),
readString(ByteArrayInputStream)public static byte[] shortToByteArray(short value)
value - Short value to convert to byte array.byteArrayToShort(byte[])public static byte[] stringToByteArray(String value)
value - String to convert to byte array.NullPointerException - if value == null.byteArrayToString(byte[])public static byte[] swapByteArray(byte[] source)
source - Byte array to swap.© Copyright 2014–2014 Digi International Inc. All rights reserved.