Class DebugUtils


  • public final class DebugUtils
    extends Object

    DebugUtils: Debugging utilties.

    • Constructor Summary

      Constructors 
      Constructor Description
      DebugUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.File byteArrayToFile​(byte[] data, String filePath)
      Dump a buffer of bytes to a file.
      static boolean doesStackContainMethod​(String methodName)
      Examine current stack trace to determine if the specified method name in the the trace.
      static String formatBytes​(byte[] data)
      Format byte array for printing.
      static String formatBytes​(byte[] data, boolean showIndex)
      Format byte array for printing.
      static String formatBytes​(byte[] data, int offset, int len)
      Format byte array for printing.
      static String formatBytes​(byte[] data, int offset, int len, boolean showIndex)
      Format byte array for printing.
      static String formatBytesInSingleRow​(byte[] data, int offset, int len)
      Format byte array for printing.
      static String formatBytesShort​(byte[] data)
      Format byte array for printing.
      static String formatBytesShort​(byte[] data, int offset, int len)
      Format byte array for printing.
      static String formatBytesStruct​(byte[] data)  
      static String formatBytesStruct​(byte[] data, int offset, int len)
      Format byte array for printing.
      static String formatMilliseconds​(long ms)
      Give a time in seconds, return a String representing the time in hh:mm:ss.mmm.
      static String formatSeconds​(long t)
      Give a time in seconds, return a String representing the time in hh:mm:ss.
      static String formatUtcTime​(long utcTime)  
      static String stackTraceToSingleLineString​(Throwable e, int maxLines)
      Given an exception, return single line String representation.
      static String stackTraceToString​(Throwable e)
      Given an exception, return String representation.
      static String stackTraceToString​(Throwable e, int maxLines, String seperator)
      Given an exception, return single line String representation.
      static String toHex​(byte value)
      Format a byte value to a 0xff format
      static String toHex​(int value)
      Format a byte value to a 0xffffffff format
      static String toLong​(long value)
      Format a long value to a 0xffffffffffffffff format
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DebugUtils

        public DebugUtils()
    • Method Detail

      • formatBytesShort

        public static String formatBytesShort​(byte[] data)
        Format byte array for printing. Simple format as rows of hex values (16 values per row)
        Parameters:
        data - byte array
        Returns:
        formatted string
      • formatBytesShort

        public static String formatBytesShort​(byte[] data,
                                              int offset,
                                              int len)
        Format byte array for printing. Simple format as rows of hex values (16 values per row)
        Parameters:
        data - byte array
        offset - offset in array
        len - data len
        Returns:
        formatted string
      • formatBytes

        public static String formatBytes​(byte[] data)
        Format byte array for printing. Format as rows of hex values (16 values per row) along with text representation of data.
        Parameters:
        data - byte array
        Returns:
        formatted string
      • formatBytes

        public static String formatBytes​(byte[] data,
                                         boolean showIndex)
        Format byte array for printing. Format as rows of hex values (16 values per row) along with text representation of data.
        Parameters:
        data - byte array
        Returns:
        formatted string
      • formatBytes

        public static String formatBytes​(byte[] data,
                                         int offset,
                                         int len)
        Format byte array for printing. Format as rows of hex values (16 values per row) along with text representation of data.
        Parameters:
        data - byte array
        offset - start index in array
        len - length to format
        Returns:
        formatted string
      • formatBytes

        public static String formatBytes​(byte[] data,
                                         int offset,
                                         int len,
                                         boolean showIndex)
        Format byte array for printing. Format as rows of hex values (16 values per row) along with text representation of data.
        Parameters:
        data - byte array
        offset - start index in array
        len - length to format
        Returns:
        formatted string
      • formatBytesInSingleRow

        public static String formatBytesInSingleRow​(byte[] data,
                                                    int offset,
                                                    int len)
        Format byte array for printing. Format as rows of hex values al in one row along with text representation of data.
        Parameters:
        data - byte array
        offset - start index in array
        len - length to format
        Returns:
        formatted string
      • formatBytesStruct

        public static String formatBytesStruct​(byte[] data)
      • formatBytesStruct

        public static String formatBytesStruct​(byte[] data,
                                               int offset,
                                               int len)
        Format byte array for printing. Format as Java primitive byte values (8 per row).
        Parameters:
        data - byte array
        Returns:
        formatted string
      • toHex

        public static String toHex​(byte value)
        Format a byte value to a 0xff format
        Parameters:
        value - byte value
        Returns:
        return string
      • toHex

        public static String toHex​(int value)
        Format a byte value to a 0xffffffff format
        Parameters:
        value - int value
        Returns:
        return string
      • toLong

        public static String toLong​(long value)
        Format a long value to a 0xffffffffffffffff format
        Parameters:
        value - long value
        Returns:
        return string
      • byteArrayToFile

        public static java.io.File byteArrayToFile​(byte[] data,
                                                   String filePath)
        Dump a buffer of bytes to a file. Useful for debugging.
        Parameters:
        data - a buffer of bytes
        filePath - The path and filename
      • formatSeconds

        public static String formatSeconds​(long t)
        Give a time in seconds, return a String representing the time in hh:mm:ss.

        123 s --> 00:02:03

        Parameters:
        t -
        Returns:
        time representation
      • formatMilliseconds

        public static String formatMilliseconds​(long ms)
        Give a time in seconds, return a String representing the time in hh:mm:ss.mmm.

        123456 ms --> 00:02:03.456

        Parameters:
        ms -
        Returns:
        time representation
      • formatUtcTime

        public static String formatUtcTime​(long utcTime)
      • stackTraceToString

        public static String stackTraceToString​(Throwable e)
        Given an exception, return String representation. Note: this is the entire raw stack trace including tabs and line endings
        Parameters:
        e - throwable
        Returns:
        stack trace representation
      • stackTraceToSingleLineString

        public static String stackTraceToSingleLineString​(Throwable e,
                                                          int maxLines)
        Given an exception, return single line String representation. Note: line endings are replaced with "|" character. Tabs are removed.
        Parameters:
        e - throwable
        maxLines - If greater than zero, returns only first maxLines of trace
        Returns:
        stack trace info
      • stackTraceToString

        public static String stackTraceToString​(Throwable e,
                                                int maxLines,
                                                String seperator)
        Given an exception, return single line String representation. Note: line endings are replaced with "|" character. Tabs are removed.
        Parameters:
        e - throwable
        maxLines - If greater than zero, returns only first maxLines of trace
        seperator - character to replace line endings with
        Returns:
        stack trace info
      • doesStackContainMethod

        public static boolean doesStackContainMethod​(String methodName)
        Examine current stack trace to determine if the specified method name in the the trace.

        Could be enhanced quite a bit by also checking for Class and method. But simple for now.

        Parameters:
        methodName -
        Returns:
        true if in trace, else false