Package io.netty.handler.stream
Class ChunkedWriteHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.stream.ChunkedWriteHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
public class ChunkedWriteHandler extends io.netty.channel.ChannelDuplexHandlerAChannelHandlerthat adds support for writing a large data stream asynchronously neither spending a lot of memory nor gettingOutOfMemoryError. Large data streaming such as file transfer requires complicated state management in aChannelHandlerimplementation.ChunkedWriteHandlermanages such complicated states so that you can send a large data stream without difficulties.To use
ChunkedWriteHandlerin your application, you have to insert a newChunkedWriteHandlerinstance:
Once inserted, you can write aChannelPipelinep = ...; p.addLast("streamer", newChunkedWriteHandler()); p.addLast("handler", new MyHandler());ChunkedInputso that theChunkedWriteHandlercan pick it up and fetch the content of the stream chunk by chunk and write the fetched chunk downstream:Channelch = ...; ch.write(newChunkedFile(new File("video.mkv"));Sending a stream which generates a chunk intermittently
SomeChunkedInputgenerates a chunk on a certain event or timing. SuchChunkedInputimplementation often returnsnullonChunkedInput.readChunk(ChannelHandlerContext), resulting in the indefinitely suspended transfer. To resume the transfer when a new chunk is available, you have to callresumeTransfer().
-
-
Constructor Summary
Constructors Constructor Description ChunkedWriteHandler()ChunkedWriteHandler(int maxPendingWrites)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx)voidchannelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)voidflush(io.netty.channel.ChannelHandlerContext ctx)voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidresumeTransfer()Continues to fetch the chunks from the input.voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
ChunkedWriteHandler
public ChunkedWriteHandler()
-
ChunkedWriteHandler
@Deprecated public ChunkedWriteHandler(int maxPendingWrites)
Deprecated.
-
-
Method Detail
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
resumeTransfer
public void resumeTransfer()
Continues to fetch the chunks from the input.
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
flushin classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelWritabilityChangedin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelWritabilityChangedin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
-