java.lang.Object
com.cumulocity.microservice.customdecoders.api.util.DecoderUtils

public final class DecoderUtils extends Object
  • Constructor Details

    • DecoderUtils

      public DecoderUtils()
  • Method Details

    • toHexString

      public static String toHexString(byte[] bytes)
      Converts the given byte array to a hexadecimal string
      Parameters:
      bytes - the input byte array
      Returns:
      String the resultant hexadecimal string
    • hexStringToByteArray

      public static byte[] hexStringToByteArray(String str)
      Converts a hexadecimal string to a byte array
      Parameters:
      str - the input hexadecimal string
      Returns:
      byte[] the resultant byte array
    • toDateTime

      public static org.joda.time.DateTime toDateTime(long timestamp)
      Converts epoch UNIX timestamp to DateTime
      Parameters:
      timestamp - the input epoch timestamp
      Returns:
      DateTime
    • convertHexToBinary

      public static String convertHexToBinary(String hex)
      Converts hexadecimal string to binary
      Parameters:
      hex - the input hexadecimal string
      Returns:
      String the resultant binary string
    • toFloatFromHexString

      public static Float toFloatFromHexString(String input)
      Converts hexadecimal string to Float
      Parameters:
      input - the input hexadecimal string
      Returns:
      Float
    • reverseBitEndianness

      public static byte[] reverseBitEndianness(byte[] raw, boolean reverseBitEndianness)
      Converts byte[] from Big Endian to Little Endian
      Parameters:
      raw - input byte array
      reverseBitEndianness - flag for endian mode (Big/Little Endian)
      Returns:
      byte[]
    • reverse

      public static byte reverse(byte value)
      Reverse the given input byte value
      Parameters:
      value - the input byte value
      Returns:
      byte
    • toFloat

      public static float toFloat(short hbits)
      Converts short to float
      Parameters:
      hbits - input short number
      Returns:
      float
    • extractBits

      public static byte extractBits(int number, int numOfBits, int fromIndex)
      Extract a particular number of bits from a particular position in a number
      Parameters:
      number - the input number
      numOfBits - the number of bits to be extracted
      fromIndex - the position from where the bits are to be extracted
      Returns:
      byte
    • limitTo16Bits

      public static int limitTo16Bits(int inputValue)
      Limits the given integer to 16 bits
      Parameters:
      inputValue - the input integer
      Returns:
      int
    • parseAsFloatingPoint

      public static double parseAsFloatingPoint(ByteBuffer buffer)
      Parses the ByteBuffer as floating point and converts it to double
      Parameters:
      buffer - the input ByteBuffer
      Returns:
      double
    • parseAsLong

      public static long parseAsLong(ByteBuffer buffer, boolean signed)
      Parses the ByteBuffer as long and converts it to long
      Parameters:
      buffer - the input ByteBuffer
      signed - flag for signed/unsigned mode
      Returns:
      long
    • reorder

      public static byte[] reorder(byte[] raw, BIT_BYTE_WORD_ORDER order)
      Reorder the input byte array based on Bits, Bytes, Byte Word or Words
      Parameters:
      raw - input byte array
      order - the parameter based on which the byte array needs to be ordered
      Returns:
      byte[] the reordered byte array