Class Utils


  • public class Utils
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  Utils.BurningTask  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static sun.misc.Unsafe U  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.lang.Iterable<T> adaptForLoop​(java.util.Iterator<T> it)
      Adapts Iterator for Iterable.
      static void check​(java.lang.Class<?> klass, java.lang.String fieldName)  
      static void check​(java.lang.Class<?> klass, java.lang.String... fieldNames)  
      static java.lang.String[] concat​(java.lang.String[] t1, java.lang.String[] t2)  
      static int figureOutHotCPUs()
      Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity.
      static java.lang.String getCurrentJvm()  
      static java.lang.String getCurrentJvmVersion()  
      static java.lang.String getCurrentOSVersion()  
      static long getOffset​(java.lang.Class<?> klass, java.lang.String fieldName)  
      static long getPid()
      Gets PID of the current JVM.
      static long getPid​(java.lang.Process process)
      Gets the PID of the target process.
      static java.util.Properties getRecordedSystemProperties()
      We don't access the complete system properties via System.getProperties() because this would require read/write permissions to the properties.
      static java.nio.charset.Charset guessConsoleEncoding()  
      private static void indent​(java.io.PrintWriter pw, int indent)  
      static boolean isWindows()  
      static java.lang.String join​(java.lang.String[] src, java.lang.String delim)  
      static java.lang.String join​(java.util.Collection<java.lang.String> src, java.lang.String delim)  
      static java.lang.String marshalIntArray​(int[] arr)  
      static <T extends java.lang.Comparable<T>>
      T
      max​(java.util.Collection<T> ts)  
      static <T extends java.lang.Comparable<T>>
      T
      min​(java.util.Collection<T> ts)  
      static java.util.Properties readPropertiesFromCommand​(java.util.List<java.lang.String> cmd)  
      static void reflow​(java.io.PrintWriter pw, java.lang.String src, int width, int indent)  
      static java.util.Collection<java.lang.String> rewrap​(java.lang.String lines)  
      static int roundUp​(int v, int quant)  
      static java.lang.Process runAsync​(java.lang.String... cmd)  
      static java.util.Collection<java.lang.String> runWith​(java.util.List<java.lang.String> cmd)  
      private static void setAccessible​(java.lang.Object holder, java.lang.reflect.AccessibleObject o)  
      static java.util.Collection<java.lang.String> splitQuotedEscape​(java.lang.String src)  
      static int sum​(int[] arr)  
      static java.lang.String throwableToString​(java.lang.Throwable t)  
      static java.util.Collection<java.lang.String> tryWith​(java.lang.String... cmd)  
      static int[] unmarshalIntArray​(java.lang.String src)  
      • Methods inherited from class java.lang.Object

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

      • U

        private static final sun.misc.Unsafe U
    • Constructor Detail

      • Utils

        private Utils()
    • Method Detail

      • min

        public static <T extends java.lang.Comparable<T>> T min​(java.util.Collection<T> ts)
      • max

        public static <T extends java.lang.Comparable<T>> T max​(java.util.Collection<T> ts)
      • concat

        public static java.lang.String[] concat​(java.lang.String[] t1,
                                                java.lang.String[] t2)
      • join

        public static java.lang.String join​(java.util.Collection<java.lang.String> src,
                                            java.lang.String delim)
      • join

        public static java.lang.String join​(java.lang.String[] src,
                                            java.lang.String delim)
      • splitQuotedEscape

        public static java.util.Collection<java.lang.String> splitQuotedEscape​(java.lang.String src)
      • sum

        public static int sum​(int[] arr)
      • roundUp

        public static int roundUp​(int v,
                                  int quant)
      • throwableToString

        public static java.lang.String throwableToString​(java.lang.Throwable t)
      • unmarshalIntArray

        public static int[] unmarshalIntArray​(java.lang.String src)
      • marshalIntArray

        public static java.lang.String marshalIntArray​(int[] arr)
      • figureOutHotCPUs

        public static int figureOutHotCPUs()
        Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity. Some systems, notably embedded Linuxes, power down the idle CPUs and so availableProcessors() may report lower CPU count than would be present after the load-up.
        Returns:
        max CPU count
      • setAccessible

        private static void setAccessible​(java.lang.Object holder,
                                          java.lang.reflect.AccessibleObject o)
                                   throws java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalAccessException
      • guessConsoleEncoding

        public static java.nio.charset.Charset guessConsoleEncoding()
      • reflow

        public static void reflow​(java.io.PrintWriter pw,
                                  java.lang.String src,
                                  int width,
                                  int indent)
      • indent

        private static void indent​(java.io.PrintWriter pw,
                                   int indent)
      • rewrap

        public static java.util.Collection<java.lang.String> rewrap​(java.lang.String lines)
      • check

        public static void check​(java.lang.Class<?> klass,
                                 java.lang.String... fieldNames)
      • check

        public static void check​(java.lang.Class<?> klass,
                                 java.lang.String fieldName)
      • getOffset

        public static long getOffset​(java.lang.Class<?> klass,
                                     java.lang.String fieldName)
      • isWindows

        public static boolean isWindows()
      • getCurrentJvm

        public static java.lang.String getCurrentJvm()
      • getCurrentJvmVersion

        public static java.lang.String getCurrentJvmVersion()
      • getCurrentOSVersion

        public static java.lang.String getCurrentOSVersion()
      • getPid

        public static long getPid()
        Gets PID of the current JVM.
        Returns:
        PID.
      • getPid

        public static long getPid​(java.lang.Process process)
        Gets the PID of the target process.
        Parameters:
        process - to poll
        Returns:
        PID, or zero if no PID is found
      • tryWith

        public static java.util.Collection<java.lang.String> tryWith​(java.lang.String... cmd)
      • runAsync

        public static java.lang.Process runAsync​(java.lang.String... cmd)
      • runWith

        public static java.util.Collection<java.lang.String> runWith​(java.util.List<java.lang.String> cmd)
      • getRecordedSystemProperties

        public static java.util.Properties getRecordedSystemProperties()
        We don't access the complete system properties via System.getProperties() because this would require read/write permissions to the properties. Just copy the properties we want to record in the result.
        Returns:
        Copy of system properties we want to record in the results.
      • readPropertiesFromCommand

        public static java.util.Properties readPropertiesFromCommand​(java.util.List<java.lang.String> cmd)
      • adaptForLoop

        public static <T> java.lang.Iterable<T> adaptForLoop​(java.util.Iterator<T> it)
        Adapts Iterator for Iterable. Can be iterated only once!
        Type Parameters:
        T - element type
        Parameters:
        it - iterator
        Returns:
        iterable for given iterator