|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.common.io.Resources
@Beta public final class Resources
Provides utility methods for working with resources in the classpath.
Note that even though these methods use URL
parameters, they
are usually not appropriate for HTTP or other non-classpath resources.
All method parameters must be non-null unless documented otherwise.
Method Summary | ||
---|---|---|
static void |
copy(URL from,
OutputStream to)
Copies all bytes from a URL to an output stream. |
|
static URL |
getResource(Class<?> contextClass,
String resourceName)
Returns a URL pointing to resourceName that is relative to
contextClass , if the resource is found in the class path. |
|
static URL |
getResource(String resourceName)
Returns a URL pointing to resourceName if the resource is
found in the class path. |
|
static InputSupplier<InputStream> |
newInputStreamSupplier(URL url)
Returns a factory that will supply instances of InputStream that
read from the given URL. |
|
static InputSupplier<InputStreamReader> |
newReaderSupplier(URL url,
Charset charset)
Returns a factory that will supply instances of InputStreamReader that read a URL using the given character set. |
|
static List<String> |
readLines(URL url,
Charset charset)
Reads all of the lines from a URL. |
|
static
|
readLines(URL url,
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(URL url)
Reads all bytes from a URL into a byte array. |
|
static String |
toString(URL url,
Charset charset)
Reads all characters from a URL into a String , using the given
character set. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static InputSupplier<InputStream> newInputStreamSupplier(URL url)
InputStream
that
read from the given URL.
url
- the URL to read from
public static InputSupplier<InputStreamReader> newReaderSupplier(URL url, 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 constants
public static byte[] toByteArray(URL url) throws IOException
url
- the URL to read from
IOException
- if an I/O error occurspublic static String toString(URL url, Charset charset) throws 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 constants
IOException
- if an I/O error occurs.public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback) throws 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 lines
IOException
- if an I/O error occurspublic static List<String> readLines(URL url, Charset charset) throws IOException
url
- the URL to read fromcharset
- the charset used to decode the input stream; see Charsets
for helpful predefined constants
List
containing all the lines
IOException
- if an I/O error occurspublic static void copy(URL from, OutputStream to) throws IOException
from
- the URL to read fromto
- the output stream
IOException
- if an I/O error occurspublic static URL getResource(String resourceName)
URL
pointing to resourceName
if the resource is
found in the class path. Resources.class.getClassLoader()
is used
to locate the resource.
IllegalArgumentException
- if resource is not foundpublic static URL getResource(Class<?> contextClass, String resourceName)
URL
pointing to resourceName
that is relative to
contextClass
, if the resource is found in the class path.
IllegalArgumentException
- if resource is not found
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |