net.sf.mmm.util.resource.base
Class AbstractDataResource

java.lang.Object
  extended by net.sf.mmm.util.resource.base.AbstractDataResource
All Implemented Interfaces:
DataResource
Direct Known Subclasses:
AbstractBrowsableResource, ClasspathResource, UrlResource

public abstract class AbstractDataResource
extends Object
implements DataResource

This is the abstract base implementation of the DataResource interface.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Constructor Summary
AbstractDataResource()
          The constructor.
 
Method Summary
 String getName()
          This method gets the name of the resource.
 String getPath()
          This method gets the path of this resource.
abstract  String getSchemePrefix()
          This method gets the scheme-prefix of absolute URIs for this type of DataResource.
 long getSize()
          This method gets the size (content-length) of this resource.
 String getUri()
          This method gets a string identifying this DataResource.
 boolean isAvailable()
          This method determines if this resource is available.
 Boolean isModifiedSince(Date date)
          This method determines if this resource has been been modified since the given data.
 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()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.resource.api.DataResource
getLastModificationDate, getUrl, isData, navigate
 

Constructor Detail

AbstractDataResource

public AbstractDataResource()
The constructor.

Method Detail

getSchemePrefix

public abstract String getSchemePrefix()
This method gets the scheme-prefix of absolute URIs for this type of DataResource. The scheme-prefix has the following form: <scheme>:<suffix> where <suffix> is the empty string or something like //.

Returns:
the scheme-prefix of this resource.

getSize

public long getSize()
             throws ResourceNotAvailableException
This method gets the size (content-length) of this resource. This is a default implementation. Override if there is a more performing way to implement this.

Specified by:
getSize in interface DataResource
Returns:
the size of this resource.
Throws:
ResourceNotAvailableException - if this resource is NOT available.

openStream

public InputStream openStream()
This method opens this resource for reading. This is a default implementation. Override if there is a more performing way to implement this.

Specified by:
openStream in interface DataResource
Returns:
the input stream where to read from.
See Also:
URL.openStream()

getPath

public String getPath()
This method gets the path of this resource. Please note that the path is including the name of the resource.
ATTENTION:
The result of this method may differ to the path used in the URL when this resource has been created.

Specified by:
getPath in interface DataResource
Returns:
the path that was used to identify this resource when creating.

getUri

public String getUri()
This method gets a string identifying this DataResource. In most cases this will be the same as string-representation of the URL. However this method will not throw an exception.

Specified by:
getUri in interface DataResource
Returns:
the URI as string.

isAvailable

public boolean isAvailable()
This method determines if this resource is available. Available simply means that it exists and data can be read.
ATTENTION:
Depending on the underlying implementation this can be a relatively expensive operation. E.g. if this resource points to a remote URL this method has to open a network connection in order to verify if the resource is available. Use DataResource.isData() to prevent such expensive operaitons.

Specified by:
isAvailable in interface DataResource
Returns:
true if this resource is available, false otherwise.

isModifiedSince

public Boolean isModifiedSince(Date date)
This method determines if this resource has been been modified since the given data.

Specified by:
isModifiedSince in interface DataResource
Parameters:
date - is the Date to check for.
Returns:
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).

openOutputStream

public OutputStream openOutputStream()
                              throws ResourceNotAvailableException,
                                     ResourceNotWritableException,
                                     RuntimeIoException
This method opens an output-stream in order to write data to the resource.

Specified by:
openOutputStream in interface DataResource
Returns:
the OutputStream to write to the resource.
Throws:
ResourceNotAvailableException - if this resource is NOT available.
ResourceNotWritableException - if the resource is NOT writable (e.g. read-only).
RuntimeIoException - if an input/output error occurred.

getName

public String getName()
This method gets the name of the resource. It is analog to a filename.

Specified by:
getName in interface DataResource
Returns:
the name of the resource.

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2001-2010 mmm-Team. All Rights Reserved.