Package org.moera.lib.util
Class Util
java.lang.Object
org.moera.lib.util.Util
A utility class that provides a collection of various helper methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
Decodes a Base64-encoded string into its corresponding byte array.static String
base64encode
(byte[] bytes) Encodes the given byte array into a Base64-encoded string.static String
base64urlencode
(byte[] bytes) Encodes the given byte array into a Base64 URL-safe encoded string without padding.static String
dump
(byte[] bytes) Converts a byte array into a space-separated string of hexadecimal values.static String
dumpShort
(byte[] bytes) Converts a byte array into a condensed string representation.static String
formatTimestamp
(long timestamp) Formats a given timestamp (in epoch seconds) into a string representation using the ISO-8601 date and time format.static String
hexByte
(byte b) Converts a single byte into a two-character uppercase hexadecimal string.static boolean
Checks whether a given string is eithernull
or empty.static Timestamp
now()
Returns the current timestamp based on the system's current time.static Long
toEpochSecond
(Timestamp timestamp) Converts aTimestamp
object to epoch seconds.static Timestamp
toTimestamp
(Long epochSecond) Converts a given epoch second value into aTimestamp
.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
now
Returns the current timestamp based on the system's current time.- Returns:
- a
Timestamp
object representing the current time
-
toEpochSecond
Converts aTimestamp
object to epoch seconds.- Parameters:
timestamp
- theTimestamp
to be converted; may benull
- Returns:
- the number of seconds since the epoch, or
null
if the input isnull
-
toTimestamp
Converts a given epoch second value into aTimestamp
. If the input isnull
, this method returnsnull
.- Parameters:
epochSecond
- the epoch second value to be converted; may benull
- Returns:
- a
Timestamp
object representing the given epoch second, ornull
if the input isnull
-
formatTimestamp
Formats a given timestamp (in epoch seconds) into a string representation using the ISO-8601 date and time format.- Parameters:
timestamp
- the timestamp in epoch seconds to format- Returns:
- a string representation of the given timestamp in ISO-8601 format
-
base64encode
Encodes the given byte array into a Base64-encoded string.- Parameters:
bytes
- the byte array to be encoded; must not benull
- Returns:
- a Base64-encoded string representation of the input byte array
-
base64decode
Decodes a Base64-encoded string into its corresponding byte array.- Parameters:
s
- the Base64-encoded string to be decoded; must not benull
- Returns:
- the decoded byte array corresponding to the input string
-
base64urlencode
Encodes the given byte array into a Base64 URL-safe encoded string without padding. If the input byte array isnull
, this method returnsnull
.- Parameters:
bytes
- the byte array to be encoded; may benull
- Returns:
- a Base64 URL-safe encoded string representation of the input byte array,
or
null
if the input isnull
-
dump
Converts a byte array into a space-separated string of hexadecimal values. Each byte is formatted as a two-character hexadecimal string.- Parameters:
bytes
- the byte array to be converted; must not benull
- Returns:
- a string representation of the input byte array
-
dumpShort
Converts a byte array into a condensed string representation. If the byte array length is 16 or less, the entire array is represented in hexadecimal format. Otherwise, the first and last 8 bytes are represented in hexadecimal format, separated by"..."
.- Parameters:
bytes
- the byte array to be converted; must not benull
- Returns:
- a condensed string representation of the input byte array
-
hexByte
Converts a single byte into a two-character uppercase hexadecimal string. If the byte is negative, it is treated as an unsigned value.- Parameters:
b
- the byte to be converted- Returns:
- a two-character hexadecimal string representation of the given byte
-
isEmpty
Checks whether a given string is eithernull
or empty.- Parameters:
s
- the string to be checked; may benull
- Returns:
true
if the string isnull
or empty,false
otherwise
-