public class Util extends Object
Generic collection of utility methods.
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static void |
copy(InputStream in,
OutputStream out) |
static File |
file(File f,
String... pathParts) |
static File |
file(String... pathParts) |
static int |
getJavaVersion()
Returns the Java version as an int value.
|
static List<Integer> |
intArrayToList(int[] ints) |
static int |
parseInt(String valueFor) |
static Path |
pathFrom(URL localArtifactUrl) |
static byte[] |
readBytes(InputStream is)
This method consumes an input stream and returns its content.
|
static <T> T[] |
reverse(T[] array) |
static <T extends Throwable> |
sneakyThrow(Throwable t)
Re-throw
t (even if it’s a checked exception) without requiring a throws declaration. |
public static int getJavaVersion()
Returns the Java version as an int value.
public static void copy(InputStream in, OutputStream out) throws IOException
IOException
public static byte[] readBytes(InputStream is) throws IOException
This method consumes an input stream and returns its content.
is
- The input stream to read from.IOException
- Error reading from stream.public static <T> T[] reverse(T[] array)
public static int parseInt(String valueFor)
public static <T extends Throwable> RuntimeException sneakyThrow(Throwable t) throws T extends 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
T extends Throwable