rabbit.httpio
Class FileResourceSource

java.lang.Object
  extended by rabbit.httpio.FileResourceSource
All Implemented Interfaces:
ResourceSource, Transferable
Direct Known Subclasses:
CacheResourceSource

public class FileResourceSource
extends Object
implements ResourceSource

A resource that comes from a file.

Author:
Robert Olofsson

Field Summary
protected  BufferHandle bufHandle
           
protected  FileChannel fc
           
 
Constructor Summary
FileResourceSource(File f, NioHandler nioHandler, BufferHandler bufHandler)
          Create a new FileResourceSource using the given filename
FileResourceSource(String filename, NioHandler nioHandler, BufferHandler bufHandler)
          Create a new FileResourceSource using the given filename
 
Method Summary
 void addBlockListener(BlockListener listener)
          Generally we do not come into this method, but it can happen..
 long length()
          Get the length of the resource in bytes.
 void release()
          Release any held resources.
 boolean supportsTransfer()
          FileChannels can be used, will always return true.
 long transferTo(long position, long count, WritableByteChannel target)
          Transfers bytes from this channel's file to the given writable byte channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fc

protected FileChannel fc

bufHandle

protected BufferHandle bufHandle
Constructor Detail

FileResourceSource

public FileResourceSource(String filename,
                          NioHandler nioHandler,
                          BufferHandler bufHandler)
                   throws IOException
Create a new FileResourceSource using the given filename

Parameters:
filename - the file for this resource
nioHandler - the NioHandler to use for background tasks
bufHandler - the BufferHandler to use when reading and writing
Throws:
IOException - if the file is a valid file

FileResourceSource

public FileResourceSource(File f,
                          NioHandler nioHandler,
                          BufferHandler bufHandler)
                   throws IOException
Create a new FileResourceSource using the given filename

Parameters:
f - the resource
nioHandler - the NioHandler to use for background tasks
bufHandler - the BufferHandler to use when reading and writing
Throws:
IOException - if the file is a valid file
Method Detail

supportsTransfer

public boolean supportsTransfer()
FileChannels can be used, will always return true.

Specified by:
supportsTransfer in interface ResourceSource
Returns:
true

length

public long length()
Description copied from interface: Transferable
Get the length of the resource in bytes.

Specified by:
length in interface Transferable
Returns:
the size of the resource or -1 if unknown.

transferTo

public long transferTo(long position,
                       long count,
                       WritableByteChannel target)
                throws IOException
Description copied from interface: Transferable
Transfers bytes from this channel's file to the given writable byte channel.

Specified by:
transferTo in interface Transferable
Parameters:
position - The position within the file at which the transfer is to begin; must be non-negative
count - The maximum number of bytes to be transferred; must be non-negative
target - The target channel
Returns:
The number of bytes, possibly zero, that were actually transferred
Throws:
IOException - if data transfer fails
See Also:
transferTo

addBlockListener

public void addBlockListener(BlockListener listener)
Generally we do not come into this method, but it can happen..

Specified by:
addBlockListener in interface ResourceSource
Parameters:
listener - the listener that will get notified when data is available

release

public void release()
Description copied from interface: ResourceSource
Release any held resources.

Specified by:
release in interface ResourceSource