Class TUtils
java.lang.Object
com.thecsdev.common.util.TUtils
TheCSDev's common utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic final ScheduledExecutorServicePrimaryExecutors.newSingleThreadScheduledExecutor()instance commonly used by this mod.static final StackWalkerDeprecated.static final ExecutorServicePrimaryExecutors.newVirtualThreadPerTaskExecutor()instance commonly used by this mod.static final @NotNull Stringstr2pbkdf2(@NotNull String input, byte @NotNull [] salt, int iterations) Hashes aStringusing PBKDF2 with HMAC-SHA256.static final @NotNull Stringstr2sha256base36(@NotNull String input) Hashes the given input string using SHA-256 and encodes the hash as a base36String.static final voiduncheckedCall(@NotNull CheckedRunnable action) static final <T> TuncheckedSupply(@NotNull CheckedSupplier<T> supplier) Gets a value from aCheckedSupplier, throwing aRuntimeExceptionif saidCheckedSupplierthrows anException.
-
Method Details
-
getStackWalkerRCR
Deprecated.Returns theStackWalkerinstance with theStackWalker.Option.RETAIN_CLASS_REFERENCEoption.- API Note:
- Very expensive for performance. Avoid using this.
-
getSingleThreadScheduledExecutor
PrimaryExecutors.newSingleThreadScheduledExecutor()instance commonly used by this mod.The scheduled executor's
Threadis a daemon thread.- See Also:
-
getVirtualThreadPerTaskExecutor
PrimaryExecutors.newVirtualThreadPerTaskExecutor()instance commonly used by this mod. -
uncheckedCall
public static final void uncheckedCall(@NotNull @NotNull CheckedRunnable action) throws NullPointerException, RuntimeException - Parameters:
action- The action to run.- Throws:
NullPointerException- If the argument is null.RuntimeException- If theCheckedRunnablethrows.
-
uncheckedSupply
public static final <T> T uncheckedSupply(@NotNull @NotNull CheckedSupplier<T> supplier) throws NullPointerException, RuntimeException Gets a value from aCheckedSupplier, throwing aRuntimeExceptionif saidCheckedSupplierthrows anException.- Parameters:
supplier- The supplier to get the value from.- Returns:
- The value supplied by the supplier.
- Throws:
NullPointerException- If the argument is null.RuntimeException- If theCheckedSupplierthrows.
-
str2sha256base36
@NotNull public static final @NotNull String str2sha256base36(@NotNull @NotNull String input) throws NullPointerException, RuntimeException Hashes the given input string using SHA-256 and encodes the hash as a base36String.- Parameters:
input- The input string to hash.- Throws:
NullPointerException- If the argument isnull.RuntimeException- If the SHA-256 algorithm is not available.
-
str2pbkdf2
@NotNull public static final @NotNull String str2pbkdf2(@NotNull @NotNull String input, byte @NotNull [] salt, int iterations) throws NullPointerException, IllegalArgumentException, RuntimeException Hashes aStringusing PBKDF2 with HMAC-SHA256.- Parameters:
input- The string to hash.salt- The salt to use for hashing.iterations- The number of iterations to use.- Returns:
- The hex-encoded hash.
- Throws:
NullPointerException- If an argument isnull.IllegalArgumentException- If iterations is less than 1.RuntimeException- If the hashing algorithm is unavailable.
-