ikrs.httpd.resource
Class RangedResource

java.lang.Object
  extended by ikrs.httpd.resource.AbstractResource
      extended by ikrs.httpd.resource.ResourceDelegation
          extended by ikrs.httpd.resource.RangedResource
All Implemented Interfaces:
Resource

public class RangedResource
extends ResourceDelegation

The RangedResource class is a wrapper class that allows to 'cut off' some bytes at the beginning and/or at the end of an existing resource. The amount of bytes to be dropped is specified by a ContentRange instance passed to the constructor. Actually the RangedResource uses a custom getInputStream() replacement with a nested ReadLimit- (to drop trailing bytes) and BytePosition-InputStream (to drop leading bytes).


Constructor Summary
RangedResource(Resource resource, ContentRange range, HTTPHandler handler, CustomLogger logger)
           
 
Method Summary
 java.io.InputStream getInputStream()
          Get the input stream from this resource.
 long getLength()
          This method returns the *actual* length of the underlying resource.
static void main(java.lang.String[] argv)
          This method is for testing only.
 void open(boolean readOnly)
          This method opens the underlying resource.
 
Methods inherited from class ikrs.httpd.resource.ResourceDelegation
close, getCoreResource, getHypertextAccessFile, getMetaData, getOutputStream, getReadLock, getWriteLock, isOpen, isReadOnly
 
Methods inherited from class ikrs.httpd.resource.AbstractResource
getHTTPHandler, getLogger, setHypertextAccessFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangedResource

public RangedResource(Resource resource,
                      ContentRange range,
                      HTTPHandler handler,
                      CustomLogger logger)
               throws java.lang.NullPointerException,
                      java.lang.IndexOutOfBoundsException
Throws:
java.lang.NullPointerException
java.lang.IndexOutOfBoundsException
Method Detail

open

public 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
Overrides:
open in class ResourceDelegation
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:
ResourceDelegation.isReadOnly()

getInputStream

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

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

getLength

public 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
Overrides:
getLength in class ResourceDelegation
Returns:
the length of the resource's data in bytes.
Throws:
java.io.IOException - If any IO error occurs.

main

public static void main(java.lang.String[] argv)
This method is for testing only.