Package alluxio.util

Class FormatUtils


  • @ThreadSafe
    public final class FormatUtils
    extends java.lang.Object
    Utility methods to parse specific formats, print according to specific formats or transform among different formats. They are not only bound to string format but also include parsing objects to a specific string format, parsing a specific string format back to objects and printing or logging according to a specific format.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String byteArrayToHexString​(byte[] bytes)
      Parses a byte array into a space separated hex string where each byte is represented in the format 0x%02x.
      static java.lang.String byteArrayToHexString​(byte[] bytes, java.lang.String prefix, java.lang.String separator)
      Parses a byte array into a hex string where each byte is represented in the format %02x.
      static java.lang.String byteBufferToString​(java.nio.ByteBuffer buf)
      Parses a ByteBuffer into a String.
      static java.lang.String formatMode​(short mode, boolean directory, boolean hasExtended)
      Formats digital representation of a model as a human-readable string.
      static java.lang.String formatTimeTakenMs​(long startTimeMs, java.lang.String message)
      Formats time elapsed since the given start time (in milliseconds).
      static java.lang.String formatTimeTakenNs​(long startTimeNs, java.lang.String message)
      Formats time elapsed since the given start time (in nanoseconds).
      static java.lang.String getSizeFromBytes​(long bytes)
      Returns a human-readable version of bytes 10GB 2048KB etc.
      static java.lang.String parametersToString​(java.lang.Object... objs)
      Parses a list of Objects into a String.
      static long parseSpaceSize​(java.lang.String spaceSize)
      Parses a String size to Bytes.
      static long parseTimeSize​(java.lang.String timeSize)
      Parses a String size to Milliseconds.
      • Methods inherited from class java.lang.Object

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

      • parametersToString

        public static java.lang.String parametersToString​(java.lang.Object... objs)
        Parses a list of Objects into a String.
        Parameters:
        objs - a list of Objects to convert to a String
        Returns:
        comma-separated concatenation of the string representation returned by Object#toString of the individual objects
      • byteBufferToString

        public static java.lang.String byteBufferToString​(java.nio.ByteBuffer buf)
        Parses a ByteBuffer into a String. In particular, the function prints the content of the buffer in 4-byte increments as space separated integers.
        Parameters:
        buf - buffer to use
        Returns:
        the String representation of the ByteBuffer
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] bytes)
        Parses a byte array into a space separated hex string where each byte is represented in the format 0x%02x.
        Parameters:
        bytes - the byte array to be transformed
        Returns:
        the string representation of the byte array
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] bytes,
                                                            java.lang.String prefix,
                                                            java.lang.String separator)
        Parses a byte array into a hex string where each byte is represented in the format %02x.
        Parameters:
        bytes - the byte array to be transformed
        prefix - the prefix to use
        separator - the separator to use
        Returns:
        the string representation of the byte array
      • formatTimeTakenMs

        public static java.lang.String formatTimeTakenMs​(long startTimeMs,
                                                         java.lang.String message)
        Formats time elapsed since the given start time (in milliseconds).
        Parameters:
        startTimeMs - start time in milliseconds
        message - prefix for the message to be printed
        Returns:
        formatted string with the elapsed time (in milliseconds)
      • formatTimeTakenNs

        public static java.lang.String formatTimeTakenNs​(long startTimeNs,
                                                         java.lang.String message)
        Formats time elapsed since the given start time (in nanoseconds).
        Parameters:
        startTimeNs - start time in nanoseconds
        message - prefix for the message to be printed
        Returns:
        formatted string with the elapsed time (in nanoseconds)
      • getSizeFromBytes

        public static java.lang.String getSizeFromBytes​(long bytes)
        Returns a human-readable version of bytes 10GB 2048KB etc.
        Parameters:
        bytes - the number of bytes
        Returns:
        human readable version
      • parseSpaceSize

        public static long parseSpaceSize​(java.lang.String spaceSize)
        Parses a String size to Bytes.
        Parameters:
        spaceSize - the size of a space, e.g. 10GB, 5TB, 1024
        Returns:
        the space size in bytes
      • parseTimeSize

        public static long parseTimeSize​(java.lang.String timeSize)
        Parses a String size to Milliseconds. Supports negative numbers.
        Parameters:
        timeSize - the size of a time, e.g. 1M, 5H, 10D, -1
        Returns:
        the time size in milliseconds
      • formatMode

        public static java.lang.String formatMode​(short mode,
                                                  boolean directory,
                                                  boolean hasExtended)
        Formats digital representation of a model as a human-readable string.
        Parameters:
        mode - file mode
        directory - if the mode corresponds to a directory
        hasExtended - true if extended acls exist
        Returns:
        human-readable version of the given mode