Class FormatUtil


  • public class FormatUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      FormatUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean customToString​(java.lang.Throwable ex)
      Returns true if the given throwable uses a custom implementation of toString()
      static java.lang.String formatByteSize​(long numBytes)
      Formats a size of bytes, appropriately rounding to bytes, kb, mb, etc
      static java.lang.String formatDateFull​(java.util.Date value)
      Returns a date formated to yyyy-MM-dd hh:mm:ss.S
      static java.lang.String formatDuration​(long millis)
      Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"
      static java.lang.String formatDuration​(long millis, FormatUtil.DurationFormatStyle style)  
      static java.lang.String formatDuration​(java.util.Locale locale, long millis)
      Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"
      static java.lang.String formatDuration​(java.util.Locale locale, long millis, FormatUtil.DurationFormatStyle style)  
      static java.lang.String formatDuration​(java.util.Locale locale, long millis, FormatUtil.DurationFormatStyle style, boolean alwaysShowMillis)  
      static java.lang.String formatDurationSince​(long millisStart)
      Shortcut, equivalent to formatDuration(System.currentTimeMillis()-millisStart)
      static java.lang.String formatDurationSince​(long millisStart, FormatUtil.DurationFormatStyle style)  
      static java.lang.String formatDurationSinceNano​(long nanoStart)
      Convenience function for using nanoTime for diffs.
      static java.lang.String formatSafe​(java.lang.String value, java.lang.Object... formatArgs)
      Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw.
      static java.lang.String formatSafe​(org.apache.log4j.Logger log, java.lang.String value, java.lang.Object... formatArgs)
      Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw.
      static java.lang.String getStacktraceCompact​(java.lang.Throwable ex)  
      static java.lang.String getStacktraceFull​(java.lang.Throwable ex)  
      • Methods inherited from class java.lang.Object

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

      • FormatUtil

        public FormatUtil()
    • Method Detail

      • formatByteSize

        public static java.lang.String formatByteSize​(long numBytes)
        Formats a size of bytes, appropriately rounding to bytes, kb, mb, etc
      • formatDurationSince

        public static java.lang.String formatDurationSince​(long millisStart)
        Shortcut, equivalent to formatDuration(System.currentTimeMillis()-millisStart)
      • formatDurationSinceNano

        public static java.lang.String formatDurationSinceNano​(long nanoStart)
        Convenience function for using nanoTime for diffs. Note, however, that internally the value is converted to milliseconds, so this is not useful for formatting sub-millisecond values.
      • formatDuration

        public static java.lang.String formatDuration​(long millis)
        Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"
      • formatDuration

        public static java.lang.String formatDuration​(java.util.Locale locale,
                                                      long millis)
        Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"
      • formatDuration

        public static java.lang.String formatDuration​(java.util.Locale locale,
                                                      long millis,
                                                      FormatUtil.DurationFormatStyle style,
                                                      boolean alwaysShowMillis)
      • customToString

        public static boolean customToString​(java.lang.Throwable ex)
        Returns true if the given throwable uses a custom implementation of toString()
      • getStacktraceCompact

        public static java.lang.String getStacktraceCompact​(java.lang.Throwable ex)
      • getStacktraceFull

        public static java.lang.String getStacktraceFull​(java.lang.Throwable ex)
      • formatDateFull

        public static java.lang.String formatDateFull​(java.util.Date value)
        Returns a date formated to yyyy-MM-dd hh:mm:ss.S
      • formatSafe

        public static java.lang.String formatSafe​(java.lang.String value,
                                                  java.lang.Object... formatArgs)
        Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw. If formatArgs is null, no operation is performed and the value is returned.
      • formatSafe

        public static java.lang.String formatSafe​(org.apache.log4j.Logger log,
                                                  java.lang.String value,
                                                  java.lang.Object... formatArgs)
        Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw. If formatArgs is null, no operation is performed and the value is returned. If the logger parameter is not null, a warning will be logged if an error occurs.