com.intel.langutil
Class TypeConverter
- java.lang.Object
-
- com.intel.langutil.TypeConverter
-
public final class TypeConverter extends java.lang.Object
This class provides basic utilities for types conversion.
-
-
Field Summary
Fields Modifier and Type Field and Description static int
INT_BYTE_SIZE
The number of bytes used to represent an integer value.static int
LONG_BYTE_SIZE
The number of bytes used to represent an long value.static int
SHORT_BYTE_SIZE
The number of bytes used to represent a short value.
-
Constructor Summary
Constructors Constructor and Description TypeConverter()
-
Method Summary
Methods Modifier and Type Method and Description static int
bytesToInt(byte[] value, int index)
Converts the bytes from the provided array into an integer value.static long
bytesToLong(byte[] value, int index)
Converts the bytes from the provided array into a long value.static short
bytesToShort(byte[] value, int index)
Converts the bytes from the provided array into a short value.static int
intToBytes(int value, byte[] destinationArray, int destinationIndex)
Converts the provided integer value to bytes and copies the bytes into the provided destination array (most significant byte first).static int
longToBytes(long value, byte[] destinationArray, int destinationIndex)
Converts the provided long value to bytes and copies the bytes into the provided destination array (most significant byte first).static int
shortToBytes(short value, byte[] destinationArray, int destinationIndex)
Converts the provided short value to bytes and copies the bytes into the provided destination array (most significant byte first).
-
-
-
Field Detail
-
SHORT_BYTE_SIZE
public static final int SHORT_BYTE_SIZE
The number of bytes used to represent a short value.- See Also:
- Constant Field Values
-
INT_BYTE_SIZE
public static final int INT_BYTE_SIZE
The number of bytes used to represent an integer value.- See Also:
- Constant Field Values
-
LONG_BYTE_SIZE
public static final int LONG_BYTE_SIZE
The number of bytes used to represent an long value.- See Also:
- Constant Field Values
-
-
Method Detail
-
intToBytes
public static final int intToBytes(int value, byte[] destinationArray, int destinationIndex)
Converts the provided integer value to bytes and copies the bytes into the provided destination array (most significant byte first). The destination array must be big enough to contain the 4 bytes of the value.- Parameters:
value
- the value to convertdestinationArray
- destination arraydestinationIndex
- index in the destination array- Returns:
- The number of bytes copied into the destination array.
-
shortToBytes
public static final int shortToBytes(short value, byte[] destinationArray, int destinationIndex)
Converts the provided short value to bytes and copies the bytes into the provided destination array (most significant byte first). The destination array must be big enough to contain the 2 bytes of the value.- Parameters:
value
- the value to convertdestinationArray
- destination arraydestinationIndex
- index in the destination array- Returns:
- The number of bytes copied into the destination array.
-
longToBytes
public static final int longToBytes(long value, byte[] destinationArray, int destinationIndex)
Converts the provided long value to bytes and copies the bytes into the provided destination array (most significant byte first). The destination array must be big enough to contain the 8 bytes of the value.- Parameters:
value
- the value to convertdestinationArray
- destination arraydestinationIndex
- index in the destination array- Returns:
- The number of bytes copied into the destination array.
-
bytesToInt
public static final int bytesToInt(byte[] value, int index)
Converts the bytes from the provided array into an integer value. The byte order in the array must be MSB and the array must be big enough to contain the 4 bytes to be converted.- Parameters:
value
- the input array to convertindex
- index in the input array- Returns:
- The converted integer value.
-
bytesToShort
public static final short bytesToShort(byte[] value, int index)
Converts the bytes from the provided array into a short value. The byte order in the array must be MSB and the array must be big enough to contain the 2 bytes to be converted.- Parameters:
value
- the input array to convertindex
- index in the input array- Returns:
- The converted short value.
-
bytesToLong
public static final long bytesToLong(byte[] value, int index)
Converts the bytes from the provided array into a long value. The byte order in the array must be MSB and the array must be big enough to contain the 8 bytes to be converted.- Parameters:
value
- the input array to convertindex
- index in the input array- Returns:
- The converted long value.
-
-