Class RU


  • public class RU
    extends java.lang.Object
    Utility class containing static methods for common operations such as JSON serialization, URI parsing, byte conversion, and scheduling tasks. This class does not contain instance fields or constructors.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.concurrent.Executor EMPTY_EXECUTOR  
      static java.util.Random RND  
      static java.security.SecureRandom SECURE_RANDOM  
    • Constructor Summary

      Constructors 
      Constructor Description
      RU()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int availableProcessors()  
      static long bytesToLong​(byte[] bytes, int offset)  
      static long bytesToLongLittleEndian​(byte[] bytes, int offset)  
      static <T> T cast​(java.lang.Object t)  
      static <T extends java.lang.Enum<T>>
      java.lang.Class<java.lang.Enum<T>>
      castEnum​(java.lang.Class<?> raw)  
      static int ceilDiv​(int x, int y)  
      static <T> T[] concatArrays​(T[] v, T[] vv)  
      static <T> T[] concatArrays​(T v, T[] vv)  
      static void concatStackTrace​(java.lang.StackTraceElement[] st, java.lang.Throwable e)  
      static int[] convertBytesToIntArray​(byte[] bytes)  
      static short[] convertBytesToShortArray​(byte[] bytes)  
      static byte[] convertIntToByteArray​(int[] data)  
      static byte[] convertShortToByteArray​(int data)  
      static byte[] convertShortToByteArray​(short data)  
      static byte[] convertShortToByteArray​(short[] data)  
      static java.util.concurrent.Executor debugExecutor​(java.util.concurrent.Executor executor)  
      static void encodeBase64​(byte[] d, int len, it.unimi.dsi.fastutil.chars.CharConsumer rs)
      Encodes a byte array to Base64 using the specified length and character consumer.
      static void encodeBase64​(byte[] d, int len, java.lang.StringBuilder rs)
      Encodes a byte array to Base64 using the specified length and StringBuilder.
      static void encodeBase64​(byte[] d, it.unimi.dsi.fastutil.chars.CharConsumer rs)
      Encodes a byte array to Base64 using the specified character consumer.
      static void encodeBase64​(byte[] d, java.lang.StringBuilder rs)
      Encodes a byte array to Base64 using the specified StringBuilder.
      static <T> T error​(java.lang.StackTraceElement[] st, java.lang.Throwable e)  
      static <T,​E extends java.lang.Throwable>
      T
      error​(java.lang.Throwable e)  
      static <T> T errorUnsupported()  
      static java.lang.String escape​(java.lang.String s)  
      static java.lang.String escape​(java.lang.String chars, java.lang.String s)  
      static void executeShell​(java.lang.String s)  
      static void executeShellBash​(java.lang.String cmd)  
      static void executeShellBashSudo​(java.lang.String password, java.lang.String cmd)  
      static java.lang.StackTraceElement[] filterFrontAndBackStackTrace​(java.lang.StackTraceElement[] ss, java.lang.Class<?>... skipClasses)  
      static <T extends java.lang.Throwable>
      T
      filterFrontAndBackStackTrace​(T e, java.lang.Class<?>... skipClasses)  
      static java.lang.StackTraceElement[] filterStackTraceBack​(java.lang.StackTraceElement[] ss, java.lang.Class<?>... skipClasses)  
      static Flow<java.io.File> getAllPaths()  
      static double getNetLoading()  
      static int getSystemLoading()  
      static java.io.File homeDir()  
      static boolean isDeclaredInClass​(java.lang.reflect.Field f, java.lang.Class<?> rootClass)  
      static void loadLibrary​(java.lang.String libraryName)  
      static <S,​T>
      T[]
      mapArray​(S[] src, java.lang.Class<T> targetType, AFunction<S,​T> mapper)  
      static long newContextId()  
      static CTypeI<java.lang.Object> parseType​(java.lang.String s)  
      static CTypeI<java.lang.Object> parseType​(java.lang.String s, int[] i)  
      static java.net.URI parseURI​(java.lang.String s)
      Parses a string into a URI.
      static void printStackTrace()  
      static <T> void readAll​(java.util.Queue<T> q, AConsumer<T> o)  
      static <T> T[] removeElement​(T[] a, int i)  
      static CTypeI<java.lang.Object> resolveExtend​(CTypeI<?> parent, CTypeI<?> owner)  
      static void runAll​(java.util.Queue<ARunnable> q)  
      static java.util.concurrent.ScheduledFuture<?> schedule​(long periodMs, ARunnable t)
      Schedules a task to run periodically with the specified period.
      static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(long period, ARunnable t)  
      static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(long period, java.util.concurrent.TimeUnit timeUnit, ARunnable t)  
      static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(Destroyer resTo, long period, java.util.concurrent.TimeUnit timeUnit, ARunnable t)  
      static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(Destroyer resTo, java.util.concurrent.Executor executor, int durationSeconds, ARunnable task)  
      static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(java.util.concurrent.Executor executor, int durationSeconds, ARunnable t)  
      static java.io.File selfExecuteCmdJar()  
      static java.lang.String selfExecuteCmdWithoutArgs()  
      static byte[] sha1​(byte[] input)  
      static int sizeOf​(java.lang.reflect.Parameter p)  
      static void sleep​(long ms)  
      static java.lang.String[] splitWithQuotes​(java.lang.String s)  
      static boolean startWith​(byte[] src, int... vals)
      Checks if a byte array starts with specified values.
      static java.io.File tempFile()  
      static long time()  
      static void toJson​(AString s, java.lang.Object val)
      Converts an object to a JSON string, appending the result to the provided AString.
      static AString toJson​(java.lang.Object val)
      Converts an object to a JSON string.
      static java.lang.CharSequence unescape​(java.lang.CharSequence s)  
      static java.lang.invoke.MethodHandle unreflect​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.reflect.Method method)  
      static java.lang.invoke.VarHandle unreflect​(java.lang.reflect.Field f)  
      static <T> int updateMax​(T owner, java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> updater, int value)  
      static <T> long updateMax​(T owner, java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater, long value)  
      static <T> int updateMin​(T owner, java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> updater, int value)  
      static java.io.File workDir()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_EXECUTOR

        public static final java.util.concurrent.Executor EMPTY_EXECUTOR
      • RND

        public static final java.util.Random RND
      • SECURE_RANDOM

        public static final java.security.SecureRandom SECURE_RANDOM
    • Constructor Detail

      • RU

        public RU()
    • Method Detail

      • loadLibrary

        public static void loadLibrary​(java.lang.String libraryName)
      • toJson

        public static AString toJson​(java.lang.Object val)
        Converts an object to a JSON string.
        Parameters:
        val - The object to convert
        Returns:
        A JSON string representation of the object
      • sha1

        public static byte[] sha1​(byte[] input)
      • toJson

        public static void toJson​(AString s,
                                  java.lang.Object val)
        Converts an object to a JSON string, appending the result to the provided AString.
        Parameters:
        s - The AString to append the result to
        val - The object to convert
      • parseURI

        public static java.net.URI parseURI​(java.lang.String s)
                                     throws java.net.URISyntaxException
        Parses a string into a URI.
        Parameters:
        s - The string to parse
        Returns:
        A URI object
        Throws:
        java.net.URISyntaxException - If the string is not a valid URI
      • startWith

        public static boolean startWith​(byte[] src,
                                        int... vals)
        Checks if a byte array starts with specified values.
        Parameters:
        src - The byte array to check
        vals - The expected values
        Returns:
        true if the array starts with the values, false otherwise
      • encodeBase64

        public static void encodeBase64​(byte[] d,
                                        it.unimi.dsi.fastutil.chars.CharConsumer rs)
                                 throws java.lang.IllegalArgumentException
        Encodes a byte array to Base64 using the specified character consumer.
        Parameters:
        d - The byte array to encode
        rs - The character consumer to store the result
        Throws:
        java.lang.IllegalArgumentException - If the input is invalid
      • encodeBase64

        public static void encodeBase64​(byte[] d,
                                        int len,
                                        it.unimi.dsi.fastutil.chars.CharConsumer rs)
                                 throws java.lang.IllegalArgumentException
        Encodes a byte array to Base64 using the specified length and character consumer.
        Parameters:
        d - The byte array to encode
        len - The number of bytes to encode
        rs - The character consumer to store the result
        Throws:
        java.lang.IllegalArgumentException - If the input is invalid
      • encodeBase64

        public static void encodeBase64​(byte[] d,
                                        java.lang.StringBuilder rs)
                                 throws java.lang.IllegalArgumentException
        Encodes a byte array to Base64 using the specified StringBuilder.
        Parameters:
        d - The byte array to encode
        rs - The StringBuilder to store the result
        Throws:
        java.lang.IllegalArgumentException - If the input is invalid
      • encodeBase64

        public static void encodeBase64​(byte[] d,
                                        int len,
                                        java.lang.StringBuilder rs)
                                 throws java.lang.IllegalArgumentException
        Encodes a byte array to Base64 using the specified length and StringBuilder.
        Parameters:
        d - The byte array to encode
        len - The number of bytes to encode
        rs - The StringBuilder to store the result
        Throws:
        java.lang.IllegalArgumentException - If the input is invalid
      • schedule

        public static java.util.concurrent.ScheduledFuture<?> schedule​(long periodMs,
                                                                       ARunnable t)
        Schedules a task to run periodically with the specified period.
        Parameters:
        periodMs - The period in milliseconds
        t - The task to schedule
        Returns:
        A ScheduledFuture representing the scheduled task
      • scheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(Destroyer resTo,
                                                                                  java.util.concurrent.Executor executor,
                                                                                  int durationSeconds,
                                                                                  ARunnable task)
      • scheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(java.util.concurrent.Executor executor,
                                                                                  int durationSeconds,
                                                                                  ARunnable t)
      • scheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(long period,
                                                                                  ARunnable t)
      • scheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(Destroyer resTo,
                                                                                  long period,
                                                                                  java.util.concurrent.TimeUnit timeUnit,
                                                                                  ARunnable t)
      • scheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(long period,
                                                                                  java.util.concurrent.TimeUnit timeUnit,
                                                                                  ARunnable t)
      • parseType

        public static CTypeI<java.lang.Object> parseType​(java.lang.String s)
      • filterFrontAndBackStackTrace

        public static <T extends java.lang.Throwable> T filterFrontAndBackStackTrace​(T e,
                                                                                     java.lang.Class<?>... skipClasses)
      • filterFrontAndBackStackTrace

        public static java.lang.StackTraceElement[] filterFrontAndBackStackTrace​(java.lang.StackTraceElement[] ss,
                                                                                 java.lang.Class<?>... skipClasses)
      • filterStackTraceBack

        public static java.lang.StackTraceElement[] filterStackTraceBack​(java.lang.StackTraceElement[] ss,
                                                                         java.lang.Class<?>... skipClasses)
      • parseType

        public static CTypeI<java.lang.Object> parseType​(java.lang.String s,
                                                         int[] i)
                                                  throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • getAllPaths

        public static Flow<java.io.File> getAllPaths()
      • sizeOf

        public static int sizeOf​(java.lang.reflect.Parameter p)
      • mapArray

        public static <S,​T> T[] mapArray​(S[] src,
                                               java.lang.Class<T> targetType,
                                               AFunction<S,​T> mapper)
      • ceilDiv

        public static int ceilDiv​(int x,
                                  int y)
      • resolveExtend

        public static CTypeI<java.lang.Object> resolveExtend​(CTypeI<?> parent,
                                                             CTypeI<?> owner)
      • error

        public static <T> T error​(java.lang.StackTraceElement[] st,
                                  java.lang.Throwable e)
      • error

        public static <T,​E extends java.lang.Throwable> T error​(java.lang.Throwable e)
                                                               throws E extends java.lang.Throwable
        Throws:
        E extends java.lang.Throwable
      • availableProcessors

        public static int availableProcessors()
      • sleep

        public static void sleep​(long ms)
      • getNetLoading

        public static double getNetLoading()
      • getSystemLoading

        public static int getSystemLoading()
      • concatArrays

        public static <T> T[] concatArrays​(T v,
                                           T[] vv)
      • cast

        public static <T> T cast​(java.lang.Object t)
      • concatArrays

        public static <T> T[] concatArrays​(T[] v,
                                           T[] vv)
      • concatStackTrace

        public static void concatStackTrace​(java.lang.StackTraceElement[] st,
                                            java.lang.Throwable e)
      • updateMax

        public static <T> int updateMax​(T owner,
                                        java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> updater,
                                        int value)
      • updateMin

        public static <T> int updateMin​(T owner,
                                        java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> updater,
                                        int value)
      • updateMax

        public static <T> long updateMax​(T owner,
                                         java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater,
                                         long value)
      • readAll

        public static <T> void readAll​(java.util.Queue<T> q,
                                       AConsumer<T> o)
      • runAll

        public static void runAll​(java.util.Queue<ARunnable> q)
      • escape

        public static java.lang.String escape​(java.lang.String s)
      • escape

        public static java.lang.String escape​(java.lang.String chars,
                                              java.lang.String s)
      • unescape

        public static java.lang.CharSequence unescape​(java.lang.CharSequence s)
      • convertBytesToShortArray

        public static short[] convertBytesToShortArray​(byte[] bytes)
      • convertBytesToIntArray

        public static int[] convertBytesToIntArray​(byte[] bytes)
      • convertShortToByteArray

        public static byte[] convertShortToByteArray​(int data)
      • convertShortToByteArray

        public static byte[] convertShortToByteArray​(short data)
      • convertShortToByteArray

        public static byte[] convertShortToByteArray​(short[] data)
      • convertIntToByteArray

        public static byte[] convertIntToByteArray​(int[] data)
      • time

        public static long time()
      • bytesToLong

        public static long bytesToLong​(byte[] bytes,
                                       int offset)
      • bytesToLongLittleEndian

        public static long bytesToLongLittleEndian​(byte[] bytes,
                                                   int offset)
      • splitWithQuotes

        public static java.lang.String[] splitWithQuotes​(java.lang.String s)
      • isDeclaredInClass

        public static boolean isDeclaredInClass​(java.lang.reflect.Field f,
                                                java.lang.Class<?> rootClass)
      • executeShellBashSudo

        public static void executeShellBashSudo​(java.lang.String password,
                                                java.lang.String cmd)
      • executeShellBash

        public static void executeShellBash​(java.lang.String cmd)
      • executeShell

        public static void executeShell​(java.lang.String s)
      • castEnum

        public static <T extends java.lang.Enum<T>> java.lang.Class<java.lang.Enum<T>> castEnum​(java.lang.Class<?> raw)
      • removeElement

        public static <T> T[] removeElement​(T[] a,
                                            int i)
      • unreflect

        public static java.lang.invoke.MethodHandle unreflect​(java.lang.invoke.MethodHandles.Lookup lookup,
                                                              java.lang.reflect.Method method)
      • unreflect

        public static java.lang.invoke.VarHandle unreflect​(java.lang.reflect.Field f)
      • debugExecutor

        public static java.util.concurrent.Executor debugExecutor​(java.util.concurrent.Executor executor)
      • errorUnsupported

        public static <T> T errorUnsupported()
      • homeDir

        public static java.io.File homeDir()
      • workDir

        public static java.io.File workDir()
      • newContextId

        public static long newContextId()
      • selfExecuteCmdJar

        public static java.io.File selfExecuteCmdJar()
      • selfExecuteCmdWithoutArgs

        public static java.lang.String selfExecuteCmdWithoutArgs()
      • tempFile

        public static java.io.File tempFile()
      • printStackTrace

        public static void printStackTrace()