Class NanoUtils

java.lang.Object
org.nanonative.nano.helper.NanoUtils

public class NanoUtils extends Object
  • Field Details

    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
    • random

      protected static Random random
    • NANO_NAMES

      public static final String[][] NANO_NAMES
  • Method Details

    • hasText

      public static boolean hasText(String str)
    • formatDuration

      public static String formatDuration(long milliseconds)
    • waitForCondition

      public static boolean waitForCondition(BooleanSupplier condition)
      Waits for a condition to become true, with actions on success or timeout.
      Parameters:
      condition - The condition to wait for, returning true when met.
      Returns:
      true if the condition was met within the timeout, false otherwise.
    • waitForCondition

      public static boolean waitForCondition(BooleanSupplier condition, long timeout)
      Waits for a condition to become true, with actions on success or timeout.
      Parameters:
      condition - The condition to wait for, returning true when met.
      timeout - stops waiting after period of time to unblock the test.
      Returns:
      true if the condition was met within the timeout, false otherwise.
    • split

      public static String[] split(String input, String delimiter)
    • callerInfoStr

      public static String callerInfoStr(Class<?> source)
    • callerInfo

      public static StackTraceElement callerInfo(Class<?> source)
    • getThreadName

      public static String getThreadName(ExecutorService executorService)
    • readConfigFiles

      public static Context readConfigFiles(Context context, String profile)
    • readProfiles

      public static Context readProfiles(Context result)
    • readConfigFile

      public static Context readConfigFile(Context context, String path)
    • addConfig

      public static Context addConfig(Context context, Object key, Object value)
    • resolvePlaceHolders

      public static Context resolvePlaceHolders(Context context)
    • encodeGzip

      public static byte[] encodeGzip(byte[] data)
    • decodeZip

      public static byte[] decodeZip(byte[] data)
    • decodeGzip

      public static byte[] decodeGzip(byte[] data)
    • encodeDeflate

      public static byte[] encodeDeflate(byte[] data)
    • decodeDeflate

      public static byte[] decodeDeflate(byte[] data)
    • generateNanoName

      public static String generateNanoName(String format)
    • handleJavaError

      public static void handleJavaError(Supplier<Context> context, Throwable error)
      Handles a Java error by logging it and shutting down the application. Note: it's likely that the application won't handle OOM errors. For OOM see Context.CONFIG_OOM_SHUTDOWN_THRESHOLD.
      Parameters:
      context - The context to use for logging and shutting down the application.
      error - The error to handle.
    • tryExecute

      public static void tryExecute(Supplier<Context> context, ExRunnable operation)
    • tryExecute

      public static void tryExecute(Supplier<Context> context, ExRunnable operation, Consumer<Throwable> consumer)