public class ConfigurationSource
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static ConfigurationSource |
COMPOSITE_SOURCE
ConfigurationSource to use with
CompositeConfiguration . |
private byte[] |
data |
private java.io.File |
file |
private static java.lang.String |
HTTP |
private static java.lang.String |
HTTPS |
private long |
lastModified |
private java.lang.String |
location |
private long |
modifiedMillis |
static ConfigurationSource |
NULL_SOURCE
ConfigurationSource to use with Configurations that do not require a "real" configuration source.
|
private Source |
source |
private java.io.InputStream |
stream |
private java.net.URL |
url |
Modifier | Constructor and Description |
---|---|
private |
ConfigurationSource(byte[] data,
java.net.URL url,
long lastModified) |
|
ConfigurationSource(java.io.InputStream stream)
Constructs a new
ConfigurationSource with the specified input stream. |
|
ConfigurationSource(java.io.InputStream stream,
java.io.File file)
Constructs a new
ConfigurationSource with the specified input stream that originated from the specified
file. |
|
ConfigurationSource(java.io.InputStream stream,
java.net.URL url)
Constructs a new
ConfigurationSource with the specified input stream that originated from the specified
url. |
|
ConfigurationSource(java.io.InputStream stream,
java.net.URL url,
long lastModified)
Constructs a new
ConfigurationSource with the specified input stream that originated from the specified
url. |
|
ConfigurationSource(Source source,
byte[] data,
long lastModified) |
Modifier and Type | Method and Description |
---|---|
static ConfigurationSource |
fromResource(java.lang.String resource,
java.lang.ClassLoader loader)
Retrieves the configuration via the ClassLoader.
|
static ConfigurationSource |
fromUri(java.net.URI configLocation)
Loads the configuration from a URI.
|
java.io.File |
getFile()
Returns the file configuration source, or
null if this configuration source is based on an URL or has
neither a file nor an URL. |
java.io.InputStream |
getInputStream()
Returns the input stream that this configuration source was constructed with.
|
long |
getLastModified()
Returns the time the resource was last modified or 0 if it is not available.
|
java.lang.String |
getLocation()
Returns a string describing the configuration source file or URL, or
null if this configuration source
has neither a file nor an URL. |
java.net.URI |
getURI()
Returns a URI representing the configuration resource or null if it cannot be determined.
|
java.net.URL |
getURL()
Returns the configuration source URL, or
null if this configuration source is based on a file or has
neither a file nor an URL. |
ConfigurationSource |
resetInputStream()
Returns a new
ConfigurationSource whose input stream is reset to the beginning. |
void |
setData(byte[] data) |
void |
setModifiedMillis(long modifiedMillis) |
void |
setSource(Source source) |
private static byte[] |
toByteArray(java.io.InputStream inputStream)
Returns the contents of the specified
InputStream as a byte array. |
java.lang.String |
toString() |
public static final ConfigurationSource NULL_SOURCE
public static final ConfigurationSource COMPOSITE_SOURCE
CompositeConfiguration
.private static final java.lang.String HTTPS
private static final java.lang.String HTTP
private final java.io.File file
private final java.net.URL url
private final java.lang.String location
private final java.io.InputStream stream
private volatile byte[] data
private volatile Source source
private final long lastModified
private volatile long modifiedMillis
public ConfigurationSource(java.io.InputStream stream, java.io.File file)
ConfigurationSource
with the specified input stream that originated from the specified
file.stream
- the input streamfile
- the file where the input stream originatedpublic ConfigurationSource(java.io.InputStream stream, java.net.URL url)
ConfigurationSource
with the specified input stream that originated from the specified
url.stream
- the input streamurl
- the URL where the input stream originatedpublic ConfigurationSource(java.io.InputStream stream, java.net.URL url, long lastModified)
ConfigurationSource
with the specified input stream that originated from the specified
url.stream
- the input streamurl
- the URL where the input stream originatedlastModified
- when the source was last modified.public ConfigurationSource(java.io.InputStream stream) throws java.io.IOException
ConfigurationSource
with the specified input stream. Since the stream is the only source
of data, this constructor makes a copy of the stream contents.stream
- the input streamjava.io.IOException
- if an exception occurred reading from the specified streampublic ConfigurationSource(Source source, byte[] data, long lastModified) throws java.io.IOException
java.io.IOException
private ConfigurationSource(byte[] data, java.net.URL url, long lastModified)
private static byte[] toByteArray(java.io.InputStream inputStream) throws java.io.IOException
InputStream
as a byte array.inputStream
- the stream to readjava.io.IOException
- if a problem occurred reading from the streampublic java.io.File getFile()
null
if this configuration source is based on an URL or has
neither a file nor an URL.null
public java.net.URL getURL()
null
if this configuration source is based on a file or has
neither a file nor an URL.null
public void setSource(Source source)
public void setData(byte[] data)
public void setModifiedMillis(long modifiedMillis)
public java.net.URI getURI()
public long getLastModified()
public java.lang.String getLocation()
null
if this configuration source
has neither a file nor an URL.null
public java.io.InputStream getInputStream()
public ConfigurationSource resetInputStream() throws java.io.IOException
ConfigurationSource
whose input stream is reset to the beginning.ConfigurationSource
java.io.IOException
- if a problem occurred while opening the new input streampublic java.lang.String toString()
toString
in class java.lang.Object
public static ConfigurationSource fromUri(java.net.URI configLocation)
configLocation
- A URI representing the location of the configuration.public static ConfigurationSource fromResource(java.lang.String resource, java.lang.ClassLoader loader)
resource
- The resource to load.loader
- The default ClassLoader to use.