Package i5.las2peer.registry
Class Util
java.lang.Object
i5.las2peer.registry.Util
Helper methods mostly for converting data.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
bytesToHexString
(byte[] byteArray) static <T> T
getOrDefault
(T value, T defaultValue) Returns the value of the first parameter if it is not null and the second param otherwisestatic byte[]
padAndConvertString
(String string, int desiredLength) Converts string to byte array, padded with zero bytes, using UTF-8 encoding.static int[]
parseVersion
(String versionString) Converts version string ("x.y.z") to integers.static String
recoverString
(byte[] byteArray) Recovers string from byte array with possible leading zeros.static String
recoverString
(String hexString) Recovers string from byte-encoded hex string.static byte[]
soliditySha3
(String input) Computes Sha3 (= Keccak256) sum, hopefully matching the sum produced by Solidity's keccak256 and web3's soliditySha3.static String
unixtimeToString
(long unixSeconds) Returns human-readable time string.
-
Method Details
-
padAndConvertString
Converts string to byte array, padded with zero bytes, using UTF-8 encoding.- Parameters:
string
- input string. Must be no longer thandesiredLength
desiredLength
- length of the returned byte array
-
recoverString
Recovers string from byte-encoded hex string. (E.g., the hex strings in transactions / event logs.) Assumes UTF-8 encoding.- Parameters:
hexString
- hexadecimal string containing Unicode- Returns:
- decoded string
-
recoverString
Recovers string from byte array with possible leading zeros. Assumes UTF-8 encoding.- Parameters:
byteArray
- Unicode byte array. Leading zeros are allowed and will be trimmed before decoding.- Returns:
- decoded string
-
bytesToHexString
-
soliditySha3
Computes Sha3 (= Keccak256) sum, hopefully matching the sum produced by Solidity's keccak256 and web3's soliditySha3.- Parameters:
input
- arbitrary input string- Returns:
- hash of input
-
parseVersion
Converts version string ("x.y.z") to integers. If the string has the form "x.y" or "x", the unspecified components are assumed to be zero. (E.g., "1" = [1,0,0].)- Parameters:
versionString
- version consisting of digits and up to three periods. Components must be parsable as Integers.- Returns:
- equivalent version as int array of length three
-
unixtimeToString
Returns human-readable time string.- Parameters:
unixSeconds
- Unix time in seconds- Returns:
- date and time as string
-
getOrDefault
public static <T> T getOrDefault(T value, T defaultValue) Returns the value of the first parameter if it is not null and the second param otherwise- Parameters:
value
-defaultValue
-- Returns:
-