public class ChunkedWriteHandler
extends io.netty.channel.ChannelDuplexHandler
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:
Once inserted, you can write aChannelPipelinep = ...; p.addLast("streamer", newChunkedWriteHandler()); p.addLast("handler", new MyHandler());
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:
Channelch = ...; ch.write(newChunkedFile(new File("video.mkv"));
Some ChunkedInput generates a chunk on a certain event or timing.
Such ChunkedInput implementation often returns null on
ChunkedInput.readChunk(ByteBufAllocator), resulting in the indefinitely suspended
transfer. To resume the transfer when a new chunk is available, you have to
call resumeTransfer().
| 构造器和说明 |
|---|
ChunkedWriteHandler(LongSupplier maxBufferBytes) |
ChunkedWriteHandler(Queue<com.github.netty.core.util.ChunkedWriteHandler.PendingWrite> queue,
LongSupplier maxBufferBytes) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) |
void |
discard(Throwable cause) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
long |
getMaxBufferBytes() |
Collection<com.github.netty.core.util.ChunkedWriteHandler.PendingWrite> |
getUnFlushList() |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
resumeTransfer()
Continues to fetch the chunks from the input.
|
void |
setMaxBufferBytes(LongSupplier maxBufferBytes) |
String |
toString() |
int |
unWriteSize() |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
public ChunkedWriteHandler(LongSupplier maxBufferBytes)
public ChunkedWriteHandler(Queue<com.github.netty.core.util.ChunkedWriteHandler.PendingWrite> queue, LongSupplier maxBufferBytes)
public void setMaxBufferBytes(LongSupplier maxBufferBytes)
public Collection<com.github.netty.core.util.ChunkedWriteHandler.PendingWrite> getUnFlushList()
public long getMaxBufferBytes()
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerAdded 在接口中 io.netty.channel.ChannelHandlerhandlerAdded 在类中 io.netty.channel.ChannelHandlerAdapterExceptionpublic void resumeTransfer()
public void write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise)
throws Exception
write 在接口中 io.netty.channel.ChannelOutboundHandlerwrite 在类中 io.netty.channel.ChannelDuplexHandlerExceptionpublic void flush(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
flush 在接口中 io.netty.channel.ChannelOutboundHandlerflush 在类中 io.netty.channel.ChannelDuplexHandlerExceptionpublic void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelInactive 在接口中 io.netty.channel.ChannelInboundHandlerchannelInactive 在类中 io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelWritabilityChanged 在接口中 io.netty.channel.ChannelInboundHandlerchannelWritabilityChanged 在类中 io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic int unWriteSize()
public void discard(Throwable cause)
Copyright © 2021. All rights reserved.