Class DecoderUtils
java.lang.Object
com.cumulocity.microservice.customdecoders.api.util.DecoderUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertHexToBinary(String hex) Converts hexadecimal string to binarystatic byteextractBits(int number, int numOfBits, int fromIndex) Extract a particular number of bits from a particular position in a numberstatic byte[]Converts a hexadecimal string to a byte arraystatic intlimitTo16Bits(int inputValue) Limits the given integer to 16 bitsstatic doubleparseAsFloatingPoint(ByteBuffer buffer) Parses the ByteBuffer as floating point and converts it to doublestatic longparseAsLong(ByteBuffer buffer, boolean signed) Parses the ByteBuffer as long and converts it to longstatic byte[]reorder(byte[] raw, BIT_BYTE_WORD_ORDER order) Reorder the input byte array based on Bits, Bytes, Byte Word or Wordsstatic bytereverse(byte value) Reverse the given input byte valuestatic byte[]reverseBitEndianness(byte[] raw, boolean reverseBitEndianness) Converts byte[] from Big Endian to Little Endianstatic org.joda.time.DateTimetoDateTime(long timestamp) Converts epoch UNIX timestamp to DateTimestatic floattoFloat(short hbits) Converts short to floatstatic FloattoFloatFromHexString(String input) Converts hexadecimal string to Floatstatic StringtoHexString(byte[] bytes) Converts the given byte array to a hexadecimal string
-
Constructor Details
-
DecoderUtils
public DecoderUtils()
-
-
Method Details
-
toHexString
Converts the given byte array to a hexadecimal string- Parameters:
bytes- the input byte array- Returns:
- String the resultant hexadecimal string
-
hexStringToByteArray
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
Converts hexadecimal string to binary- Parameters:
hex- the input hexadecimal string- Returns:
- String the resultant binary string
-
toFloatFromHexString
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 arrayreverseBitEndianness- 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 numbernumOfBits- the number of bits to be extractedfromIndex- 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
Parses the ByteBuffer as floating point and converts it to double- Parameters:
buffer- the input ByteBuffer- Returns:
- double
-
parseAsLong
Parses the ByteBuffer as long and converts it to long- Parameters:
buffer- the input ByteBuffersigned- flag for signed/unsigned mode- Returns:
- long
-
reorder
Reorder the input byte array based on Bits, Bytes, Byte Word or Words- Parameters:
raw- input byte arrayorder- the parameter based on which the byte array needs to be ordered- Returns:
- byte[] the reordered byte array
-