Class ByteUtils

java.lang.Object
org.xrpl.xrpl4j.codec.addresses.ByteUtils

public class ByteUtils extends Object
Utilities to work with bytes in an XRPL context.
  • Constructor Details

    • ByteUtils

      public ByteUtils()
  • Method Details

    • toByteArray

      public static byte[] toByteArray(int value, int byteSize)
      Converts an int to a byte array of the expected size, left padded with 0 bytes.
      Parameters:
      value - The int value to convert.
      byteSize - The final size of the byte[].
      Returns:
      A byte[] with the converted value, left padded with 0 bytes.
    • toByteArray

      public static byte[] toByteArray(BigInteger value, int byteSize)
      Converts a BigInteger to a byte array of the expected size, left padded with 0 bytes.
      Parameters:
      value - The BigInteger to convert.
      byteSize - The final size of the byte[].
      Returns:
      A byte[] with the converted value, left padded with 0 bytes.
    • parse

      public static List<UnsignedByte> parse(String hex)
      Parses a hexadecimal String to a List of UnsignedBytes.
      Parameters:
      hex - A hexadecimal String to parse.
      Returns:
      A List of UnsignedBytes containing the parsed hex.
    • checkSize

      public static BigInteger checkSize(int expectedBits, BigInteger value)
      Checks that the given BigInteger value has a bitsize (binary) less than or equal to the expectedBits.

      This is used to make sure a value can fit in a field with a fixed bit size.

      Parameters:
      expectedBits - The expected number of bits in value
      value - The BigInteger to check.
      Returns:
      The BigInteger value.
    • toHex

      public static String toHex(List<UnsignedByte> segments)
      Converts a List of UnsignedBytes to a hexadecimal String.
      Parameters:
      segments - A List of UnsignedBytes to convert.
      Returns:
      A hexadecimal String.
    • toUnsignedLong

      public static com.google.common.primitives.UnsignedLong toUnsignedLong(UnsignedByteArray segments)
      Converts an UnsignedByteArray to an UnsignedLong.
      Parameters:
      segments - The UnsignedByteArray to convert.
      Returns:
      The UnsignedLong value of segments.
    • padded

      public static String padded(String hex)
      Pads a hex string to one that has an even number of characters. For example "F" becomes "0F" and "FF" remains "FF" since it already as an even number.
      Parameters:
      hex - The hex String to pad.
      Returns:
      A left padded hex String.
    • padded

      public static String padded(String hex, int hexLength)
      Pads a hex string to one that has the expected number of characters. For example padded("FF", 4) yields "00FF"
      Parameters:
      hex - The hex String to pad.
      hexLength - The length of the final padded hex String.
      Returns:
      A left padded hex String with the given length.