Package org.robolectric.util
Class Util
- java.lang.Object
-
- org.robolectric.util.Util
-
public class Util extends java.lang.ObjectGeneric collection of utility methods.
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopy(java.io.InputStream in, java.io.OutputStream out)static java.io.Filefile(java.io.File f, java.lang.String... pathParts)static java.io.Filefile(java.lang.String... pathParts)static intgetJavaVersion()Returns the Java version as an int value.static java.util.List<java.lang.Integer>intArrayToList(int[] ints)static intparseInt(java.lang.String valueFor)static java.nio.file.PathpathFrom(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.RuntimeExceptionsneakyThrow(java.lang.Throwable t)Re-throwt(even if it's a checked exception) without requiring athrowsdeclaration.
-
-
-
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.IOExceptionThis 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.ThrowableRe-throwt(even if it's a checked exception) without requiring athrowsdeclaration.This function declares a return type of
RuntimeExceptionbut will never actually return a value. This allows you to use it with athrowstatement 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
-
-