Class ByteUtil

java.lang.Object
net.osslabz.evm.abi.util.ByteUtil

public class ByteUtil extends Object
  • Constructor Details

    • ByteUtil

      public ByteUtil()
  • Method Details

    • toHexString

      public static String toHexString(byte[] data)
      Convert a byte-array into a hex String.
      Works similar to Hex.toHexString(byte[]) but allows for null
      Parameters:
      data - - byte-array to convert to a hex-string
      Returns:
      hex representation of the data.
      Returns an empty String if the input is null
      See Also:
      • Hex.toHexString(byte[])
    • bytesToBigInteger

      public static BigInteger bytesToBigInteger(byte[] bb)
    • bigIntegerToBytes

      public static byte[] bigIntegerToBytes(BigInteger value)
      Omitting sign indication byte.

      Instead of org.spongycastle.util.BigIntegers#asUnsignedByteArray(BigInteger
      we use this custom method to avoid an empty array in case of BigInteger.ZERO
      Parameters:
      value - - any big integer number. A null-value will return null
      Returns:
      A byte array without a leading zero byte if present in the signed encoding. BigInteger.ZERO will return an array with length 1 and byte-value 0.
    • bigIntegerToBytes

      public static byte[] bigIntegerToBytes(BigInteger b, int numBytes)
      The regular BigInteger.toByteArray() method isn't quite what we often need: it appends a leading zero to indicate that the number is positive and may need padding.
      Parameters:
      b - the integer to format into a byte array
      numBytes - the desired size of the resulting byte array
      Returns:
      numBytes byte long array.
    • bigIntegerToBytesSigned

      public static byte[] bigIntegerToBytesSigned(BigInteger b, int numBytes)
    • merge

      public static byte[] merge(byte[]... arrays)
      Parameters:
      arrays - - arrays to merge
      Returns:
      - merged array