Package biz.onixs.util
Class Utils
- java.lang.Object
-
- biz.onixs.util.Utils
-
public class Utils extends Object
Utility class containing various helper methods.
-
-
Field Summary
Fields Modifier and Type Field Description static StringUNSAFE_CHARACTERSRegular expression for unsafe characters.static StringWHITE_SPACEWhite space characters.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringensureCanonicalName(String fileName)Ensures that the given file name is in a canonical form by replacing unsafe characters with underscores.static StringhumanReadableByteCount(long bytes)Converts a bytes number to a human-readable string representation.static booleanisStringEmpty(String s)Checks if the given string is empty or null.static byte[]subArray(byte[] source, int length)Creates a sub-array from the given source array up to the specified length.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.static StringsystemProperties2String()Converts system properties to a string representation.static StringtrimWhiteSpace(String value)Trims leading and trailing white space from the given string.static voidwaitForEnter()Waits for the user to press Enter.static voidwaitForEnter(String message)Waits for the user to press Enter and displays a custom message.static voidwaitForEnterToTerminateApp()Waits for the user to press Enter and displays a termination message.
-
-
-
Field Detail
-
UNSAFE_CHARACTERS
public static final String UNSAFE_CHARACTERS
Regular expression for unsafe characters.- See Also:
- Constant Field Values
-
WHITE_SPACE
public static final String WHITE_SPACE
White space characters.- See Also:
- Constant Field Values
-
-
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.
-
-