Class FileChannelStagelet

  extended by
All Implemented Interfaces:
Handlet, Stagelet
Direct Known Subclasses:

public class FileChannelStagelet
extends Object
implements Stagelet

Serves the contents of an HTTP response from a FileChannel. Note, the instance will own the position of the given file channel after the init method is invoked. This class does not rewind the file channel to zero before writing: whatever it's value at init, that value will denote the beginning of the file.

Babak Farhang

Field Summary
protected  FileChannel content
Constructor Summary
FileChannelStagelet(FileChannel content, StageletStack stack, boolean persistConnection, boolean head)
          Creates a new instance.
Method Summary
 void discard()
          Closes the content stream
 ResponseHeaderStage getHeaders()
          Returns the HTTP response header stage.
 IoState init(HandletContext context)
          Initializes the handlet.
 IoState read(ScatteringByteChannel in)
          Not used.
 IoState state()
          Returns the state of the handlet.
 IoState unwind(IoState preState)
          Callback method invoked when the previous stage[let] returned DONE.
 IoState write(GatheringByteChannel out)
          Writes to the specified channel and returns the possibly new state of the instance.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected FileChannel content
Constructor Detail


public FileChannelStagelet(FileChannel content,
                           StageletStack stack,
                           boolean persistConnection,
                           boolean head)
Creates a new instance.

content - the channel from which the content will be served. If null, then the response will be "Not Found" (404).
stack - the execution stack. Must not be null
persistConnection - if false, then the response headers shall include "Connection: close".
Method Detail


public ResponseHeaderStage getHeaders()
Returns the HTTP response header stage. The headers may only be modified before the init(HandletContext) is invoked. O.w., an exception will be raised on invoking a mutator method on the returned object.


public IoState unwind(IoState preState)
Description copied from interface: Stagelet
Callback method invoked when the previous stage[let] returned DONE. In the event this method returns DONE, the stack will call the Handlet.discard() method on the super interface.

Specified by:
unwind in interface Stagelet
preState - the state of the previous stage prior to its flipping to DONE
the state of this stage. If DONE, and there is another Stagelet on the execution stack, then that stage's unwind() method will also be invoked with the same preState argument.


public void discard()
Closes the content stream

Specified by:
discard in interface Handlet


public IoState init(HandletContext context)
Description copied from interface: Handlet
Initializes the handlet.

Specified by:
init in interface Handlet
context - the context supplied by the instance's container (e.g. server


public IoState read(ScatteringByteChannel in)
             throws IOException
Not used.

Specified by:
read in interface Handlet


public IoState state()
Description copied from interface: Handlet
Returns the state of the handlet.

Specified by:
state in interface Handlet


public IoState write(GatheringByteChannel out)
              throws IOException
Description copied from interface: Handlet
Writes to the specified channel and returns the possibly new state of the instance. Note that if the return value is IoState.PROCESSING, then a later invocation of Handlet.state() may return a value other than PROCESSING, if the asynchronous task completes before the call to state().

The implementation must write to the channel in non-blocking manner. The behavior of this method is undefined if the state of the instance is not IoState.WRITING.

Specified by:
write in interface Handlet
IOException Logo