Class ByteUtils


  • public final class ByteUtils
    extends java.lang.Object
    Utilities class for Byte related operations
    Since:
    0.1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ByteUtils.HexCase
      Hex string code case selector
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String encodeHexString​(byte[] byteArray)
      Encodes a byte array to an hex string in lower case as default
      static java.lang.String encodeHexString​(byte[] byteArray, ByteUtils.HexCase hexCase)
      Encodes a byte array to an hex string
      static byte[] parseHexString​(java.lang.String hexString)
      Parses a hex string to byte array
      static void reverse​(byte[] bytes)
      Reverses a byte array, used to change endian
      static void reverse​(byte[] bytes, int from, int to)
      Reverses a byte array, used to change endian
      • Methods inherited from class java.lang.Object

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

      • ByteUtils

        public ByteUtils()
    • Method Detail

      • reverse

        public static void reverse​(byte[] bytes)
        Reverses a byte array, used to change endian
        Parameters:
        bytes - array of bytes to reverse
      • reverse

        public static void reverse​(byte[] bytes,
                                   int from,
                                   int to)
        Reverses a byte array, used to change endian
        Parameters:
        bytes - array of bytes to reverse
        from - first byte position to swap
        to - last byte position to swap
      • parseHexString

        public static byte[] parseHexString​(java.lang.String hexString)
                                     throws java.lang.IllegalArgumentException
        Parses a hex string to byte array
        Parameters:
        hexString - the hex string to parse
        Returns:
        the encoded byte array
        Throws:
        java.lang.IllegalArgumentException - thrown if hexString is invalid
      • encodeHexString

        public static java.lang.String encodeHexString​(byte[] byteArray)
        Encodes a byte array to an hex string in lower case as default
        Parameters:
        byteArray - the byte array to encode
        Returns:
        the encoded hex string
      • encodeHexString

        public static java.lang.String encodeHexString​(byte[] byteArray,
                                                       ByteUtils.HexCase hexCase)
        Encodes a byte array to an hex string
        Parameters:
        byteArray - the byte array to encode
        hexCase - upper or lower hex code case to use
        Returns:
        the encoded hex string