Class ByteUtils

java.lang.Object
com.nimbusds.jose.util.ByteUtils

public class ByteUtils extends Object
Byte utilities.
Version:
2022-04-22
Author:
Vladimir Dzhuvinov
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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 boolean
    isZeroFilled(byte[] byteArray)
    Returns true if the specified byte array is zero filled.
    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.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • 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.
    • isZeroFilled

      public static boolean isZeroFilled(byte[] byteArray)
      Returns true if the specified byte array is zero filled.
      Parameters:
      byteArray - the byte array. Must not be null.
      Returns:
      true if zero filled, else false.