public final class ResourceUtil extends Object
Modifier | Constructor and Description |
---|---|
private |
ResourceUtil()
Prevent instantiation of utility class.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
getResourceAsBytes(Class<?> clazz,
String name)
Reads a resource as bytes from the the given class' class loader.
|
static byte[] |
getResourceAsBytes(String name)
Reads a resource as bytes from the context class loader.
|
static InputStream |
getResourceAsStream(Class<?> clazz,
String name)
Reads a resource as a stream from the the given class' class loader.
|
static InputStream |
getResourceAsStream(String name)
Reads a resource as a stream from the context class loader.
|
static String |
getResourceAsString(Class<?> clazz,
String name)
Reads a resource as a string from the the given class' class loader.
|
static String |
getResourceAsString(String name)
Reads a resource as a String from the from the context class loader.
|
static File |
getResourceCopy(Class<?> clazz,
String name)
Creates a copy of the resource from the given class' class loader to a
temporary file.
|
static File |
getResourceCopy(String name)
Creates a copy of the resource from the context class loader to a
temporary file.
|
static byte[] |
streamToBytes(InputStream is)
Converts an
InputStream to bytes. |
static File |
streamToTempFile(InputStream is)
Copies the contents of an
InputStream to a temporary file. |
public static byte[] getResourceAsBytes(Class<?> clazz, String name)
clazz
- classname
- name of the resourcepublic static byte[] getResourceAsBytes(String name)
name
- name of the resourcepublic static InputStream getResourceAsStream(Class<?> clazz, String name)
clazz
- classname
- name of the resourcepublic static InputStream getResourceAsStream(String name)
name
- name of the resourcepublic static String getResourceAsString(Class<?> clazz, String name)
clazz
- classname
- name of the resourcepublic static String getResourceAsString(String name)
name
- name of the resourcepublic static File getResourceCopy(Class<?> clazz, String name)
clazz
- classname
- name of the resourcepublic static File getResourceCopy(String name)
name
- name of the resourcepublic static byte[] streamToBytes(InputStream is)
InputStream
to bytes. This will not throw an
IOException
but wraps it in an AssertionError
. This reads
the InputStream
to end of file, but does not close it.is
- input streampublic static File streamToTempFile(InputStream is)
InputStream
to a temporary file. This
will not throw an IOException
but wraps it in an
AssertionError
. This reads the InputStream
to end of
file, but does not close it.is
- input streamCopyright © 2012–2015 Trajano. All rights reserved.