Class TextUtils

java.lang.Object
uno.anahata.asi.internal.TextUtils

public class TextUtils extends Object
A collection of general-purpose text and formatting utility methods.
Author:
anahata
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatBase64(byte[] data)
    Encodes a byte array to a Base64 string and truncates it for display.
    static String
    formatByteArray(byte[] data)
    Formats a byte array into a concise string representation, showing the first and last three bytes in 0-255 format and truncating the middle.
    static String
    formatSize(long size)
    Formats a byte size into a human-readable string (e.g., "1.2 KB", "5.5 MB").
    static String
    Formats a value for display in a summary, escaping newlines and truncating in the middle if necessary.
    static String
    Gets a unique identifier for the current device (hostname).
    static String
    Gets a unique identifier for the current JVM instance, including the PID and hostname.
    static String
    Gets the name of the current user.
    static boolean
    Checks if an object is null, a blank string, or an empty collection/map.
    static String
    Intelligently resolves the pure Java representation for a value.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TextUtils

      public TextUtils()
  • Method Details

    • formatSize

      public static String formatSize(long size)
      Formats a byte size into a human-readable string (e.g., "1.2 KB", "5.5 MB").
      Parameters:
      size - The size in bytes.
      Returns:
      The formatted string.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(Object value)
      Checks if an object is null, a blank string, or an empty collection/map.
      Parameters:
      value - The object to check.
      Returns:
      true if the object is considered null or empty.
    • formatValue

      public static String formatValue(Object value)
      Formats a value for display in a summary, escaping newlines and truncating in the middle if necessary.
      Parameters:
      value - The object to format.
      Returns:
      A formatted, truncated string.
    • resolveContentString

      public static String resolveContentString(Object value)
      Intelligently resolves the pure Java representation for a value.

      Technical Purity: This method bypasses JSON serialization entirely. Collections are joined with newlines for clean multi-line display, while arrays leverage a professional bracketed comma-separated format using reflection.

      Parameters:
      value - The object to represent.
      Returns:
      The raw Java string representation.
    • formatByteArray

      public static String formatByteArray(byte[] data)
      Formats a byte array into a concise string representation, showing the first and last three bytes in 0-255 format and truncating the middle.
      Parameters:
      data - The byte array to format.
      Returns:
      A formatted string (e.g., "[12, 34, 56 ... 78, 90, 12]").
    • formatBase64

      public static String formatBase64(byte[] data)
      Encodes a byte array to a Base64 string and truncates it for display.
      Parameters:
      data - The byte array.
      Returns:
      A truncated Base64 string.
    • getDeviceId

      public static String getDeviceId()
      Gets a unique identifier for the current device (hostname).
      Returns:
      The hostname, or "unknown-device" if it cannot be determined.
    • getJvmId

      public static String getJvmId()
      Gets a unique identifier for the current JVM instance, including the PID and hostname.
      Returns:
      The JVM ID in the format "pid@hostname".
    • getUserName

      public static String getUserName()
      Gets the name of the current user.
      Returns:
      The user name.