public interface Resource
create(URI)), classpath (create(String)), filesystem (create(Path),
content in config (create(Config, String), input stream(create(String, InputStream),
or direct value (create(String, byte[]), create(String, String).
The resource bytes can then be accessed by various methods, depending on the type required - either you can access bytes
(bytes(), stream()) or String (string(), string(Charset)).
This class is not thread safe. If you want to use it across multiple threads,
there is an option: call cacheBytes() before accessing it by other threads.
Note that this stores all the bytes in memory, so use with care!!!| Modifier and Type | Interface and Description |
|---|---|
static class |
Resource.Source
Source of a
Resource. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
bytes()
Get bytes of this resource.
|
void |
cacheBytes()
Caches the resource bytes in memory, so they can be repeatedly
accessed.
|
static Optional<Resource> |
create(Config config,
String keyPrefix)
Loads the resource from appropriate location based
on configuration and a key prefix.
|
static Resource |
create(Path fsPath)
Load resource from file system.
|
static Resource |
create(String resourcePath)
Load resource from classpath.
|
static Resource |
create(String description,
byte[] bytes)
Load resource from binary content.
|
static Resource |
create(String description,
InputStream inputStream)
Load resource from binary content from an input stream, using
Resource.Source.UNKNOWN type. |
static Resource |
create(String description,
String string)
Load resource from text content (e.g.
|
static Resource |
create(URI uri)
Load resource from URI provided.
|
static Resource |
create(URI uri,
Proxy proxy)
Load resource from URI provided with an explicit proxy server.
|
String |
location()
Location (or description) of this resource, depends on original source.
|
Resource.Source |
sourceType()
Type of this resource, depends on the original source.
|
InputStream |
stream()
Get an input stream to this resource.
|
String |
string()
Get string content of this resource.
|
String |
string(Charset charset)
Get string content of this resource.
|
static Resource create(URI uri)
bytes() and other
content retrieval-methods.uri - Resource locationstatic Resource create(URI uri, Proxy proxy)
bytes() and other
content retrieval-methods.uri - Resource locationproxy - HTTP proxy to use when accessing the URIstatic Resource create(String resourcePath)
bytes() and other
content retrieval-methods.resourcePath - classpath pathstatic Resource create(Path fsPath)
bytes() and other
content retrieval-methods.fsPath - path of file systemstatic Resource create(String description, byte[] bytes)
description - description of this resource (e.g. "keystore")bytes - raw bytes of this resourcestatic Resource create(String description, String string)
create(String, byte[]) for binary).description - description of this resource (e.g. "JWK-private")string - string content of this resource, will be transformed to bytes using UTF-8 encodingstatic Resource create(String description, InputStream inputStream)
Resource.Source.UNKNOWN type.description - description of this resource (e.g. "keystore")inputStream - input stream to raw bytes of this resourcestatic Optional<Resource> create(Config config, String keyPrefix)
config - configurationkeyPrefix - prefix of keys that may contain the location of resourceInputStream stream()
bytes(), or explicitly buffer
this resource cacheBytes(), you will get a new input stream to the
buffered bytes and may call this method multiple times.IllegalStateException - in case the stream was already provided in previous call and was not bufferedbyte[] bytes()
IllegalStateException - in case the stream was already provided in previous call and was not bufferedString string()
IllegalStateException - in case the stream was already provided in previous call and was not bufferedString string(Charset charset)
charset - Character set (encoding) to use to decode bytesIllegalStateException - in case the stream was already provided in previous call and was not bufferedResource.Source sourceType()
String location()
create(String, String)create(String, byte[])create(String, InputStream)void cacheBytes()
Copyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.