public abstract class AbstractDataResourceProxy extends Object implements DataResource
DataResource
interface that delegates to
another
DataResource
.Constructor and Description |
---|
AbstractDataResourceProxy()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract DataResource |
getDelegate()
This method gets the
DataResource this proxy delegates to. |
Date |
getLastModificationDate()
This method gets the last modification date of the
DataResource if available and
supported. |
String |
getName()
This method gets the name of the resource.
|
String |
getPath()
This method gets the path of this resource.
|
long |
getSize()
This method gets the size (content-length) of this resource.
|
String |
getUri()
This method gets a string identifying this
DataResource . |
URL |
getUrl()
This method gets this resource as
URL . |
boolean |
isAvailable()
This method determines if this resource is available.
|
boolean |
isData()
This method determines if this resource has potentially data
available . |
Boolean |
isModifiedSince(Date date)
This method determines if this resource has been been modified since the given
data . |
DataResource |
navigate(String relativePath)
This method retrieves a
DataResource pointing to the given resourcePath based on this resource.E.g. |
OutputStream |
openOutputStream()
This method opens an output-stream in order to write data to the resource.
|
InputStream |
openStream()
This method opens this resource for reading.
|
String |
toString() |
protected abstract DataResource getDelegate()
DataResource
this proxy delegates to.public String getPath()
DataResource
name
of
the resource. getPath
in interface DataResource
public String getName()
DataResource
filename
.getName
in interface DataResource
public long getSize()
DataResource
getSize
in interface DataResource
public URL getUrl()
DataResource
URL
.getUrl
in interface DataResource
public String getUri()
DataResource
DataResource
. In most cases this will be the same as
string-representation
of the URL
. However this method will not throw an
exception.getUri
in interface DataResource
public boolean isAvailable()
DataResource
data can be read
. DataResource.isData()
to prevent such expensive operaitons.isAvailable
in interface DataResource
true
if this resource is available, false
otherwise.public boolean isData()
DataResource
available
. Unlike
DataResource.isAvailable()
this method will not invoke expensive operations like connecting to remote URLs. If this
method will return false
, then DataResource.isAvailable()
would also have returned false
. However in
case of true
only DataResource.isAvailable()
can guarantee if a resource really exists and contains data. E.g.
if the resource points to a File
then this method can check if it is a data-file
. So in case it points to a directory or does not exist at all in the filesystem, this method will return
false
. Please also note that this may invoke expensive operations if the according directory path points to
something like a network share. You should also be aware that the state of DataResource.isData()
and
DataResource.isAvailable()
can change at any time so you never have a full guarantee if some data exists or NOT.
However in most cases it is very improbable that this status changes when you read
the
resource immediately after the check.isData
in interface DataResource
true
if this resource points to potential data, false
otherwise.public DataResource navigate(String relativePath)
DataResource
DataResource
pointing to the given resourcePath
based on this resource.resourcePath
would be "../apt/sources.list"
the resulting resource would point to "/etc/apt/sources.list". folder
of this resource. This will also be the case if this resource itself is
a folder
. Due to this generic API this is the only consistent way as there are
implementations that can not easily know if they represent a folder
or a
file
or maybe even both at the same time. However, please be aware of this and
do not get confused as you might expect this to be a cd
command if invoked on
a folder
what is not exactly not the case (instead it is a
cd
on the parent folder). On a BrowsableResource
you can use
BrowsableResource.cd(String)
instead to avoid confusion.navigate
in interface DataResource
relativePath
- the absolute or relative path pointing to a new resource. If it is a relative path, it is
interpreted relative to the parent URI (directory) of this resource.BrowsableResource.cd(String)
public InputStream openStream()
DataResource
openStream
in interface DataResource
URL.openStream()
public OutputStream openOutputStream()
DataResource
openOutputStream
in interface DataResource
OutputStream
to write to the resource.public Boolean isModifiedSince(Date date)
DataResource
data
.isModifiedSince
in interface DataResource
date
- is the Date
to check for.true
if the resource has been modified after the given date
, false
if it has NOT
been modified after the given date
and null
if this can NOT be determined (resource not
available
or operation NOT supported by this resource).public Date getLastModificationDate()
DataResource
DataResource
if available
and
supported.getLastModificationDate
in interface DataResource
Date
or null
if not available or supported.Copyright © 2001–2016 mmm-Team. All rights reserved.