Intel

Developer Zone

TypeConverter

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 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 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, getClass, 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 convert
        destinationArray - destination array
        destinationIndex - 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 convert
        destinationArray - destination array
        destinationIndex - 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 convert
        index - 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 convert
        index - index in the input array
        Returns:
        The converted short value.