Class Util


  • public class Util
    extends java.lang.Object
    Generic collection of utility methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copy​(java.io.InputStream in, java.io.OutputStream out)  
      static java.io.File file​(java.io.File f, java.lang.String... pathParts)  
      static java.io.File file​(java.lang.String... pathParts)  
      static int getJavaVersion()
      Returns the Java version as an int value.
      static java.util.List<java.lang.Integer> intArrayToList​(int[] ints)  
      static int parseInt​(java.lang.String valueFor)  
      static java.nio.file.Path pathFrom​(java.net.URL localArtifactUrl)  
      static byte[] readBytes​(java.io.InputStream is)
      This method consumes an input stream and returns its content, and closes it.
      static <T> T[] reverse​(T[] array)  
      static <T extends java.lang.Throwable>
      java.lang.RuntimeException
      sneakyThrow​(java.lang.Throwable t)
      Re-throw t (even if it's a checked exception) without requiring a throws declaration.
      • Methods inherited from class java.lang.Object

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

      • Util

        public Util()
    • Method Detail

      • getJavaVersion

        public static int getJavaVersion()
        Returns the Java version as an int value.
        Returns:
        the Java version as an int value (8, 9, etc.)
      • copy

        public static void copy​(java.io.InputStream in,
                                java.io.OutputStream out)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readBytes

        public static byte[] readBytes​(java.io.InputStream is)
                                throws java.io.IOException
        This method consumes an input stream and returns its content, and closes it.
        Parameters:
        is - The input stream to read from.
        Returns:
        The bytes read from the stream.
        Throws:
        java.io.IOException - Error reading from stream.
      • reverse

        public static <T> T[] reverse​(T[] array)
      • file

        public static java.io.File file​(java.lang.String... pathParts)
      • file

        public static java.io.File file​(java.io.File f,
                                        java.lang.String... pathParts)
      • pathFrom

        public static java.nio.file.Path pathFrom​(java.net.URL localArtifactUrl)
      • intArrayToList

        public static java.util.List<java.lang.Integer> intArrayToList​(int[] ints)
      • parseInt

        public static int parseInt​(java.lang.String valueFor)
      • sneakyThrow

        public static <T extends java.lang.Throwable> java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
                                                                                      throws T extends java.lang.Throwable
        Re-throw t (even if it's a checked exception) without requiring a throws declaration.

        This function declares a return type of RuntimeException but will never actually return a value. This allows you to use it with a throw statement to convince the compiler that the current branch will not complete.

        
         throw Util.sneakyThrow(new IOException());
         

        Adapted from https://www.mail-archive.com/javaposse@googlegroups.com/msg05984.html

        Throws:
        T extends java.lang.Throwable