org.jboss.netty.handler.stream

## Class ChunkedWriteHandler

- java.lang.Object
- - org.jboss.netty.handler.stream.ChunkedWriteHandler

All Implemented Interfaces:
  ChannelDownstreamHandler, ChannelHandler, ChannelUpstreamHandler, LifeCycleAwareChannelHandler

    public class ChunkedWriteHandler
    extends Object
    implements ChannelUpstreamHandler, ChannelDownstreamHandler, LifeCycleAwareChannelHandler

A `ChannelHandler` that adds support for writing a large data stream asynchronously neither spending a lot of memory nor getting `OutOfMemoryError`. Large data streaming such as file transfer requires complicated state management in a `ChannelHandler` implementation. `ChunkedWriteHandler` manages such complicated states so that you can send a large data stream without difficulties.

To use `ChunkedWriteHandler` in your application, you have to insert a new `ChunkedWriteHandler` instance:

     ChannelPipeline p = ...;
     p.addLast("streamer", new ChunkedWriteHandler());
     p.addLast("handler", new MyHandler());

Once inserted, you can write a `ChunkedInput` so that the `ChunkedWriteHandler` can pick it up and fetch the content of the stream chunk by chunk and write the fetched chunk downstream:

     Channel ch = ...;
     ch.write(new ChunkedFile(new File("video.mkv"));

### Sending a stream which generates a chunk intermittently

Some `ChunkedInput` generates a chunk on a certain event or timing. Such `ChunkedInput` implementation often returns `null` on `ChunkedInput.nextChunk()`, resulting in the indefinitely suspended transfer. To resume the transfer when a new chunk is available, you have to call `resumeTransfer()`.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler

`ChannelHandler.Sharable`

### Constructor Summary

Constructors
Constructor and Description
`ChunkedWriteHandler()`

### Method Summary

Methods
`void` `afterAdd(ChannelHandlerContext ctx)`
`void` `afterRemove(ChannelHandlerContext ctx)`
`void` `beforeAdd(ChannelHandlerContext ctx)`
`void` `beforeRemove(ChannelHandlerContext ctx)`
`void` `handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)` Handles the specified downstream event.
`void` `handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)` Handles the specified upstream event.
`void` `resumeTransfer()` Continues to fetch the chunks from the input.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ChunkedWriteHandler

    public ChunkedWriteHandler()

### Method Detail

#### resumeTransfer

    public void resumeTransfer()

Continues to fetch the chunks from the input.

#### handleDownstream

    public void handleDownstream(ChannelHandlerContext ctx,
                        ChannelEvent e)
                          throws Exception

Description copied from interface: `ChannelDownstreamHandler`
Handles the specified downstream event.

Specified by:
  `handleDownstream` in interface `ChannelDownstreamHandler`
Parameters:
  `ctx` - the context object for this handler
  `e` - the downstream event to process or intercept
Throws:
  `Exception`

#### handleUpstream

    public void handleUpstream(ChannelHandlerContext ctx,
                      ChannelEvent e)
                        throws Exception

Description copied from interface: `ChannelUpstreamHandler`
Handles the specified upstream event.

Specified by:
  `handleUpstream` in interface `ChannelUpstreamHandler`
Parameters:
  `ctx` - the context object for this handler
  `e` - the upstream event to process or intercept
Throws:
  `Exception`

#### beforeAdd

    public void beforeAdd(ChannelHandlerContext ctx)
                   throws Exception

Specified by:
  `beforeAdd` in interface `LifeCycleAwareChannelHandler`
Throws:
  `Exception`

#### afterAdd

    public void afterAdd(ChannelHandlerContext ctx)
                  throws Exception

Specified by:
  `afterAdd` in interface `LifeCycleAwareChannelHandler`
Throws:
  `Exception`

#### beforeRemove

    public void beforeRemove(ChannelHandlerContext ctx)
                      throws Exception

Specified by:
  `beforeRemove` in interface `LifeCycleAwareChannelHandler`
Throws:
  `Exception`

#### afterRemove

    public void afterRemove(ChannelHandlerContext ctx)
                     throws Exception

Specified by:
  `afterRemove` in interface `LifeCycleAwareChannelHandler`
Throws:
  `Exception`