@Beta
public final class Resources
extends java.lang.Object
URL parameters, they
are usually not appropriate for HTTP or other non-classpath resources.
All method parameters must be non-null unless documented otherwise.
| Modifier and Type | Method and Description |
|---|---|
static ByteSource |
asByteSource(java.net.URL url)
Returns a
ByteSource that reads from the given URL. |
static CharSource |
asCharSource(java.net.URL url,
java.nio.charset.Charset charset)
Returns a
CharSource that reads from the given URL using the given character set. |
static void |
copy(java.net.URL from,
java.io.OutputStream to)
Copies all bytes from a URL to an output stream.
|
static java.net.URL |
getResource(java.lang.Class<?> contextClass,
java.lang.String resourceName)
Returns a
URL pointing to resourceName that is relative to
contextClass, if the resource is found in the class path. |
static java.net.URL |
getResource(java.lang.String resourceName)
Returns a
URL pointing to resourceName if the resource is
found in the class path. |
static InputSupplier<java.io.InputStream> |
newInputStreamSupplier(java.net.URL url)
Returns a factory that will supply instances of
InputStream that
read from the given URL. |
static InputSupplier<java.io.InputStreamReader> |
newReaderSupplier(java.net.URL url,
java.nio.charset.Charset charset)
Returns a factory that will supply instances of
InputStreamReader that read a URL using the given character set. |
static java.util.List<java.lang.String> |
readLines(java.net.URL url,
java.nio.charset.Charset charset)
Reads all of the lines from a URL.
|
static <T> T |
readLines(java.net.URL url,
java.nio.charset.Charset charset,
LineProcessor<T> callback)
Streams lines from a URL, stopping when our callback returns false, or we
have read all of the lines.
|
static byte[] |
toByteArray(java.net.URL url)
Reads all bytes from a URL into a byte array.
|
static java.lang.String |
toString(java.net.URL url,
java.nio.charset.Charset charset)
Reads all characters from a URL into a
String, using the given
character set. |
public static InputSupplier<java.io.InputStream> newInputStreamSupplier(java.net.URL url)
InputStream that
read from the given URL.url - the URL to read frompublic static ByteSource asByteSource(java.net.URL url)
ByteSource that reads from the given URL.public static InputSupplier<java.io.InputStreamReader> newReaderSupplier(java.net.URL url, java.nio.charset.Charset charset)
InputStreamReader that read a URL using the given character set.url - the URL to read fromcharset - the charset used to decode the input stream; see Charsets for helpful predefined constantspublic static CharSource asCharSource(java.net.URL url, java.nio.charset.Charset charset)
CharSource that reads from the given URL using the given character set.public static byte[] toByteArray(java.net.URL url)
throws java.io.IOException
url - the URL to read fromjava.io.IOException - if an I/O error occurspublic static java.lang.String toString(java.net.URL url,
java.nio.charset.Charset charset)
throws java.io.IOException
String, using the given
character set.url - the URL to read fromcharset - the charset used to decode the input stream; see Charsets for helpful predefined constantsjava.io.IOException - if an I/O error occurs.public static <T> T readLines(java.net.URL url,
java.nio.charset.Charset charset,
LineProcessor<T> callback)
throws java.io.IOException
url - the URL to read fromcharset - the charset used to decode the input stream; see Charsets for helpful predefined constantscallback - the LineProcessor to use to handle the linesjava.io.IOException - if an I/O error occurspublic static java.util.List<java.lang.String> readLines(java.net.URL url,
java.nio.charset.Charset charset)
throws java.io.IOException
url - the URL to read fromcharset - the charset used to decode the input stream; see Charsets for helpful predefined constantsList containing all the linesjava.io.IOException - if an I/O error occurspublic static void copy(java.net.URL from,
java.io.OutputStream to)
throws java.io.IOException
from - the URL to read fromto - the output streamjava.io.IOException - if an I/O error occurspublic static java.net.URL getResource(java.lang.String resourceName)
URL pointing to resourceName if the resource is
found in the class path. Resources.class.getClassLoader() is used
to locate the resource.java.lang.IllegalArgumentException - if resource is not foundpublic static java.net.URL getResource(java.lang.Class<?> contextClass,
java.lang.String resourceName)
URL pointing to resourceName that is relative to
contextClass, if the resource is found in the class path.java.lang.IllegalArgumentException - if resource is not found