Class ByteUtils


  • public class ByteUtils
    extends Object
    Byte utilities.
    Version:
    2017-06-01
    Author:
    Vladimir Dzhuvinov
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int bitLength​(byte[] byteArray)
      Returns the byte length of the specified byte array.
      static int bitLength​(int byteLength)
      Returns the bit length of the specified byte length.
      static int byteLength​(int bitLength)
      Returns the byte length of the specified bit length.
      static byte[] concat​(byte[]... byteArrays)
      Concatenates the specified byte arrays.
      static int safeBitLength​(byte[] byteArray)
      Returns the byte length of the specified byte array, preventing integer overflow.
      static int safeBitLength​(int byteLength)
      Returns the bit length of the specified byte length, preventing integer overflow.
      static byte[] subArray​(byte[] byteArray, int beginIndex, int length)
      Returns a portion of the specified byte array.
    • Method Detail

      • concat

        public static byte[] concat​(byte[]... byteArrays)
        Concatenates the specified byte arrays.
        Parameters:
        byteArrays - The byte arrays to concatenate, may be null.
        Returns:
        The resulting byte array.
      • subArray

        public static byte[] subArray​(byte[] byteArray,
                                      int beginIndex,
                                      int length)
        Returns a portion of the specified byte array.
        Parameters:
        byteArray - The byte array. Must not be null.
        beginIndex - The beginning index, inclusive. Must be zero or positive.
        length - The length. Must be zero or positive.
        Returns:
        The byte array portion.
      • bitLength

        public static int bitLength​(int byteLength)
        Returns the bit length of the specified byte length.
        Parameters:
        byteLength - The byte length.
        Returns:
        The bit length.
      • safeBitLength

        public static int safeBitLength​(int byteLength)
                                 throws IntegerOverflowException
        Returns the bit length of the specified byte length, preventing integer overflow.
        Parameters:
        byteLength - The byte length.
        Returns:
        The bit length.
        Throws:
        IntegerOverflowException - On a integer overflow.
      • bitLength

        public static int bitLength​(byte[] byteArray)
        Returns the byte length of the specified byte array.
        Parameters:
        byteArray - The byte array. May be null.
        Returns:
        The bite length, zero if the array is null.
      • safeBitLength

        public static int safeBitLength​(byte[] byteArray)
                                 throws IntegerOverflowException
        Returns the byte length of the specified byte array, preventing integer overflow.
        Parameters:
        byteArray - The byte array. May be null.
        Returns:
        The bite length, zero if the array is null.
        Throws:
        IntegerOverflowException - On a integer overflow.
      • byteLength

        public static int byteLength​(int bitLength)
        Returns the byte length of the specified bit length.
        Parameters:
        bitLength - The bit length.
        Returns:
        The byte byte length.