Package org.stellar.sdk
Class Util
java.lang.Object
org.stellar.sdk.Util
Utility class for common operations.
note: For some reason we need to make it public, but I don't recommend to use it directly.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The function that converts XDR string to XDR object. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic AssetTypeCreditAlphaNum
assertNonNativeAsset
(Asset asset) ThrowsIllegalArgumentException
if the given asset is native (XLM).static String
bytesToHex
(byte[] bytes) Returns hex representation ofbytes
array.static byte[]
getBytes
(BigInteger value) Returns an 8 byte array representation of a BigInteger value.static String
Get the version of the SDKstatic byte[]
hash
(byte[] data) Returns SHA-256 hash ofdata
.static byte[]
hexToBytes
(String s) Returns byte array representation ofhex
string.static byte[]
paddedByteArray
(String string, int length) Padsstring
tolength
with zeros.static <T> T
parseXdr
(String xdr, Util.XdrDecodeFunction<String, T> fromXdrBase64) Parses XDR string to XDR object.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
bytesToHex
Returns hex representation ofbytes
array.- Parameters:
bytes
- byte array to convert to hex- Returns:
- hex representation of the byte array
-
hexToBytes
Returns byte array representation ofhex
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 ofdata
.- Parameters:
data
- byte array to hash- Returns:
- SHA-256 hash of the data
-
paddedByteArray
Padsstring
tolength
with zeros.- Parameters:
string
- string to padlength
- length of the resulting array- Returns:
- padded byte array
-
getSdkVersion
Get the version of the SDK- Returns:
- version
-
assertNonNativeAsset
ThrowsIllegalArgumentException
if the given asset is native (XLM).- Parameters:
asset
- The asset to check
-
getBytes
Returns an 8 byte array representation of a BigInteger value.- Parameters:
value
- BigInteger value to convert to byte array- Returns:
- byte array
-
parseXdr
Parses XDR string to XDR object.- Type Parameters:
T
- type of XDR object- Parameters:
xdr
- XDR stringfromXdrBase64
- function that converts XDR string to XDR object- Returns:
- XDR object, or null if the input string is null or empty
-