com.intel.langutil
Class TypeConverter
java.lang.Objectcom.intel.langutil.TypeConverter
public final class TypeConverter
- extends java.lang.Object
This class provides basic utilities for types conversion.
Field Summary | |
---|---|
static int |
INT_BYTE_SIZE
The number of bytes used to represent an integer value. |
static int |
SHORT_BYTE_SIZE
The number of bytes used to represent a short value. |
Constructor Summary | |
---|---|
TypeConverter()
|
Method Summary | |
---|---|
static int |
bytesToInt(byte[] value,
int index)
Converts the bytes from the provided array into an integer 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 |
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). |
Methods inherited from class java.lang.Object |
---|
equals, hashCode, toString |
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
Constructor Detail |
---|
TypeConverter
public TypeConverter()
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.
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.