Package io.dropwizard.util
Class Resources
- java.lang.Object
-
- io.dropwizard.util.Resources
-
public final class Resources extends Object
- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopy(URL from, OutputStream to)Copies all bytes from a URL to an output stream.static URLgetResource(String resourceName)static byte[]toByteArray(URL url)Reads all bytes from a URL into a byte array.static StringtoString(URL url, Charset charset)Reads all characters from a URL into aString, using the given character set.
-
-
-
Method Detail
-
getResource
public static URL getResource(String resourceName)
Returns aURLpointing toresourceNameif the resource is found using the context class loader. In simple environments, the context class loader will find resources from the class path. In environments where different threads can have different class loaders, for example app servers, the context class loader will typically have been set to an appropriate loader for the current thread.In the unusual case where the context class loader is null, the class loader that loaded this class (
Resources) will be used instead.- Throws:
IllegalArgumentException- if the resource is not found
-
toByteArray
public static byte[] toByteArray(URL url) throws IOException
Reads all bytes from a URL into a byte array.- Parameters:
url- the URL to read from- Returns:
- a byte array containing all the bytes from the URL
- Throws:
IOException- if an I/O error occurs
-
toString
public static String toString(URL url, Charset charset) throws IOException
Reads all characters from a URL into aString, using the given character set.- Parameters:
url- the URL to read fromcharset- the charset used to decode the input stream; seeStandardCharsetsfor helpful predefined constants- Returns:
- a string containing all the characters from the URL
- Throws:
IOException- if an I/O error occurs.
-
copy
public static void copy(URL from, OutputStream to) throws IOException
Copies all bytes from a URL to an output stream.- Parameters:
from- the URL to read fromto- the output stream- Throws:
IOException- if an I/O error occurs
-
-