Class Util

java.lang.Object
org.stellar.sdk.Util

public class Util extends Object
Utility class for common operations.

note: For some reason we need to make it public, but I don't recommend to use it directly.

  • Constructor Details

    • Util

      public Util()
  • Method Details

    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      Returns hex representation of bytes array.
      Parameters:
      bytes - byte array to convert to hex
      Returns:
      hex representation of the byte array
    • hexToBytes

      public static byte[] hexToBytes(String s)
      Returns byte array representation of hex string.
      Parameters:
      s - hex string to convert to byte array
      Returns:
      byte array representation of the hex string
    • hash

      public static byte[] hash(byte[] data)
      Returns SHA-256 hash of data.
      Parameters:
      data - byte array to hash
      Returns:
      SHA-256 hash of the data
    • paddedByteArray

      public static byte[] paddedByteArray(String string, int length)
      Pads string to length with zeros.
      Parameters:
      string - string to pad
      length - length of the resulting array
      Returns:
      padded byte array
    • getSdkVersion

      public static String getSdkVersion()
      Get the version of the SDK
      Returns:
      version
    • assertNonNativeAsset

      public static AssetTypeCreditAlphaNum assertNonNativeAsset(Asset asset)
      Throws IllegalArgumentException if the given asset is native (XLM).
      Parameters:
      asset - The asset to check
    • getBytes

      public static byte[] getBytes(BigInteger value)
      Returns an 8 byte array representation of a BigInteger value.
      Parameters:
      value - BigInteger value to convert to byte array
      Returns:
      byte array
    • parseXdr

      public static <T> T parseXdr(String xdr, Util.XdrDecodeFunction<String,T> fromXdrBase64)
      Parses XDR string to XDR object.
      Type Parameters:
      T - type of XDR object
      Parameters:
      xdr - XDR string
      fromXdrBase64 - function that converts XDR string to XDR object
      Returns:
      XDR object, or null if the input string is null or empty