ikrs.httpd.resource
Class AbstractResource

java.lang.Object
  extended by ikrs.httpd.resource.AbstractResource
All Implemented Interfaces:
Resource
Direct Known Subclasses:
AbstractDirectoryResource, BufferedResource, ByteArrayResource, FileResource, InterruptableResource, ProcessableResource, ResourceDelegation

public abstract class AbstractResource
extends java.lang.Object
implements Resource


Constructor Summary
AbstractResource(HTTPHandler handler, CustomLogger logger, boolean useFairLocks)
          Create a new AbstractResource.
 
Method Summary
abstract  boolean close()
          Closes this resource.
 HTTPHandler getHTTPHandler()
          Get the global HTTP handler.
 HypertextAccessFile getHypertextAccessFile()
          Get the resource's hypertext access file settings.
abstract  java.io.InputStream getInputStream()
          Get the input stream from this resource.
abstract  long getLength()
          This method returns the *actual* length of the underlying resource.
 CustomLogger getLogger()
           
 ResourceMetaData getMetaData()
          Get the meta data for this resource.
abstract  java.io.OutputStream getOutputStream()
          Get the output stream to this resource.
 java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock getReadLock()
          This method returns the read lock for this resource.
 java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock getWriteLock()
          This method returns the write lock for this resource.
abstract  boolean isOpen()
          This method determines if this resource was alerady opened or not.
abstract  boolean isReadOnly()
          This method returns true if the underlying resource is read-only (in general).
abstract  void open(boolean readOnly)
          This method opens the underlying resource.
protected  void setHypertextAccessFile(HypertextAccessFile hypertextAccessFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractResource

public AbstractResource(HTTPHandler handler,
                        CustomLogger logger,
                        boolean useFairLocks)
Create a new AbstractResource.

Method Detail

getHTTPHandler

public HTTPHandler getHTTPHandler()
Get the global HTTP handler.


getLogger

public CustomLogger getLogger()

setHypertextAccessFile

protected void setHypertextAccessFile(HypertextAccessFile hypertextAccessFile)

getMetaData

public ResourceMetaData getMetaData()
Get the meta data for this resource.

Specified by:
getMetaData in interface Resource

getHypertextAccessFile

public HypertextAccessFile getHypertextAccessFile()
Get the resource's hypertext access file settings. If the resource has not hypertext access settings available the method may return null.

Specified by:
getHypertextAccessFile in interface Resource

getReadLock

public java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock getReadLock()
This method returns the read lock for this resource.

Specified by:
getReadLock in interface Resource

getWriteLock

public java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock getWriteLock()
This method returns the write lock for this resource.

Specified by:
getWriteLock in interface Resource

open

public abstract void open(boolean readOnly)
                   throws java.io.IOException
This method opens the underlying resource. Don't forget to close.

Specified by:
open in interface Resource
Parameters:
readOnly - if set to true, the resource will be opned in read-only mode.
Throws:
ReadOnlyException - If the underlying resource is read-only in general.
java.io.IOException - If any other IO error occurs.
See Also:
isReadOnly()

isOpen

public abstract boolean isOpen()
                        throws java.io.IOException
This method determines if this resource was alerady opened or not.

Specified by:
isOpen in interface Resource
Throws:
java.io.IOException - If any IO error occurs.

isReadOnly

public abstract boolean isReadOnly()
                            throws java.io.IOException
This method returns true if the underlying resource is read-only (in general).

Specified by:
isReadOnly in interface Resource
Throws:
java.io.IOException - If any IO error occurs.

getLength

public abstract long getLength()
                        throws java.io.IOException
This method returns the *actual* length of the underlying resource. This length will be used in the HTTP header fields to specify the transaction length. During read-process (you used the locks, didn't you?) the length MUST NOT change.

Specified by:
getLength in interface Resource
Returns:
the length of the resource's data in bytes.
Throws:
java.io.IOException - If any IO error occurs.

getOutputStream

public abstract java.io.OutputStream getOutputStream()
                                              throws ReadOnlyException,
                                                     java.io.IOException
Get the output stream to this resource.

Specified by:
getOutputStream in interface Resource
Throws:
ReadOnlyException - If this resource was opened with the read-only flag set.
java.io.IOException - If any other IO error occurs.

getInputStream

public abstract java.io.InputStream getInputStream()
                                            throws java.io.IOException
Get the input stream from this resource.

Specified by:
getInputStream in interface Resource
Throws:
java.io.IOException - If any IO error occurs.

close

public abstract boolean close()
                       throws java.io.IOException
Closes this resource.

Specified by:
close in interface Resource
Returns:
false if the resource was already closed, false otherwise.
Throws:
java.io.IOException