Class BytesUtils


  • public final class BytesUtils
    extends java.lang.Object
    Class used to manage String/byte/int converter
    Author:
    Millau Julien
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int byteArrayToInt​(byte[] byteArray)
      Method used to convert byte array to int
      static int byteArrayToInt​(byte[] byteArray, int startPos, int length)
      Method used to convert byte array to int
      static java.lang.String bytesToString​(byte[] pBytes)
      Method to convert bytes to string with space between bytes
      static java.lang.String bytesToString​(byte[] pBytes, boolean pTruncate)
      Method to convert bytes to string with space between bytes bytes to convert
      static java.lang.String bytesToStringNoSpace​(byte pByte)
      Method to convert byte to string without space between byte
      static java.lang.String bytesToStringNoSpace​(byte[] pBytes)
      Method to convert bytes to string without space between bytes
      static java.lang.String bytesToStringNoSpace​(byte[] pBytes, boolean pTruncate)
      Method to convert bytes to string without space between bytes
      static byte[] fromString​(java.lang.String pData)
      Method to get bytes form string
      static boolean matchBitByBitIndex​(int pVal, int pBitIndex)
      Test if bit at given index of given value is = 1.
      static byte setBit​(byte pData, int pBitIndex, boolean pOn)
      Method used to set a bit index to 1 or 0.
      static java.lang.String toBinary​(byte[] pBytes)
      Convert byte array to binary String
      static byte[] toByteArray​(int value)
      Method used to convert integer to byet array
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • byteArrayToInt

        public static int byteArrayToInt​(byte[] byteArray)
        Method used to convert byte array to int
        Parameters:
        byteArray - byte array to convert
        Returns:
        int value
      • byteArrayToInt

        public static int byteArrayToInt​(byte[] byteArray,
                                         int startPos,
                                         int length)
        Method used to convert byte array to int
        Parameters:
        byteArray - byte array to convert
        startPos - start position in array in the
        length - length of data
        Returns:
        int value of byte array
      • bytesToString

        public static java.lang.String bytesToString​(byte[] pBytes)
        Method to convert bytes to string with space between bytes
        Parameters:
        pBytes - Bytes to convert
        Returns:
        a string
      • bytesToString

        public static java.lang.String bytesToString​(byte[] pBytes,
                                                     boolean pTruncate)
        Method to convert bytes to string with space between bytes bytes to convert
        Parameters:
        pBytes - Bytes to convert
        pTruncate - true to remove 0 left byte value
        Returns:
        a string
      • bytesToStringNoSpace

        public static java.lang.String bytesToStringNoSpace​(byte pByte)
        Method to convert byte to string without space between byte
        Parameters:
        pByte - byte to convert
        Returns:
        a string
      • bytesToStringNoSpace

        public static java.lang.String bytesToStringNoSpace​(byte[] pBytes)
        Method to convert bytes to string without space between bytes
        Parameters:
        pBytes - bytes to convert
        Returns:
        a string
      • bytesToStringNoSpace

        public static java.lang.String bytesToStringNoSpace​(byte[] pBytes,
                                                            boolean pTruncate)
        Method to convert bytes to string without space between bytes
        Parameters:
        pBytes - bytes to convert
        pTruncate - true to remove 0 left byte value
        Returns:
        a string
      • fromString

        public static byte[] fromString​(java.lang.String pData)
        Method to get bytes form string
        Parameters:
        pData - String to parse
        Returns:
        a table of string
      • matchBitByBitIndex

        public static boolean matchBitByBitIndex​(int pVal,
                                                 int pBitIndex)
        Test if bit at given index of given value is = 1.
        Parameters:
        pVal - value to test
        pBitIndex - bit index between 0 and 31
        Returns:
        true bit at given index of give value is = 1
      • setBit

        public static byte setBit​(byte pData,
                                  int pBitIndex,
                                  boolean pOn)
        Method used to set a bit index to 1 or 0.
        Parameters:
        pData - data to modify
        pBitIndex - index to set
        pOn - set bit at specified index to 1 or 0
        Returns:
        the modified byte
      • toBinary

        public static java.lang.String toBinary​(byte[] pBytes)
        Convert byte array to binary String
        Parameters:
        pBytes - byte array to convert
        Returns:
        a binary representation of the byte array
      • toByteArray

        public static byte[] toByteArray​(int value)
        Method used to convert integer to byet array
        Parameters:
        value - the value to convert
        Returns:
        a byte array