Package org.xrpl.xrpl4j.codec.addresses
Class ByteUtils
java.lang.Object
org.xrpl.xrpl4j.codec.addresses.ByteUtils
Utilities to work with bytes in an XRPL context.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigIntegercheckSize(int expectedBits, BigInteger value) Checks that the givenBigIntegervalue has a bitsize (binary) less than or equal to theexpectedBits.static StringPads a hex string to one that has an even number of characters.static StringPads a hex string to one that has the expected number of characters.static List<UnsignedByte> static byte[]toByteArray(int value, int byteSize) Converts an int to a byte array of the expected size, left padded with 0 bytes.static byte[]toByteArray(BigInteger value, int byteSize) Converts aBigIntegerto a byte array of the expected size, left padded with 0 bytes.static StringtoHex(List<UnsignedByte> segments) static com.google.common.primitives.UnsignedLongtoUnsignedLong(UnsignedByteArray segments) Converts anUnsignedByteArrayto anUnsignedLong.
-
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
Converts aBigIntegerto a byte array of the expected size, left padded with 0 bytes.- Parameters:
value- TheBigIntegerto convert.byteSize- The final size of the byte[].- Returns:
- A byte[] with the converted value, left padded with 0 bytes.
-
parse
- Parameters:
hex- A hexadecimalStringto parse.- Returns:
- A
ListofUnsignedBytes containing the parsed hex.
-
checkSize
Checks that the givenBigIntegervalue has a bitsize (binary) less than or equal to theexpectedBits.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 invaluevalue- TheBigIntegerto check.- Returns:
- The
BigIntegervalue.
-
toHex
- Parameters:
segments- AListofUnsignedBytes to convert.- Returns:
- A hexadecimal
String.
-
toUnsignedLong
Converts anUnsignedByteArrayto anUnsignedLong.- Parameters:
segments- TheUnsignedByteArrayto convert.- Returns:
- The
UnsignedLongvalue ofsegments.
-
padded
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. -
padded
Pads a hex string to one that has the expected number of characters. For examplepadded("FF", 4)yields "00FF"
-