Class Utils


  • public class Utils
    extends Object
    Utility class containing various helper methods.
    • Method Detail

      • subArray

        public static byte[] subArray​(byte[] source,
                                      int length)
        Creates a sub-array from the given source array up to the specified length.
        Parameters:
        source - The source byte array.
        length - The length of the sub-array.
        Returns:
        A new byte array containing the sub-array.
      • subArray

        public static byte[] subArray​(byte[] source,
                                      int offset,
                                      int length)
        Creates a sub-array from the given source array starting at the specified offset and up to the specified length.
        Parameters:
        source - The source byte array.
        offset - The starting index of the sub-array.
        length - The length of the sub-array.
        Returns:
        A new byte array containing the sub-array.
      • systemProperties2String

        public static String systemProperties2String()
        Converts system properties to a string representation.
        Returns:
        A string containing the system properties.
      • waitForEnter

        public static void waitForEnter()
        Waits for the user to press Enter.
      • waitForEnterToTerminateApp

        public static void waitForEnterToTerminateApp()
        Waits for the user to press Enter and displays a termination message.
      • waitForEnter

        public static void waitForEnter​(String message)
        Waits for the user to press Enter and displays a custom message.
        Parameters:
        message - The message to display before waiting for Enter.
      • isStringEmpty

        public static boolean isStringEmpty​(String s)
        Checks if the given string is empty or null.
        Parameters:
        s - The string to check.
        Returns:
        true if the string is empty or null, false otherwise.
      • trimWhiteSpace

        public static String trimWhiteSpace​(String value)
        Trims leading and trailing white space from the given string.
        Parameters:
        value - The string to trim.
        Returns:
        A new string with leading and trailing white space removed.
      • humanReadableByteCount

        public static String humanReadableByteCount​(long bytes)
        Converts a bytes number to a human-readable string representation.
        Parameters:
        bytes - The number of bytes to convert.
        Returns:
        A string containing the human-readable representation of the number of bytes.
      • ensureCanonicalName

        public static String ensureCanonicalName​(String fileName)
        Ensures that the given file name is in a canonical form by replacing unsafe characters with underscores.
        Parameters:
        fileName - The file name to be converted.
        Returns:
        A new string with all unsafe characters replaced by underscores.