public class HttpChunkedInput extends java.lang.Object implements ChunkedInput<HttpContent>
ChunkedInput ,通过块获取数据块以便与HTTP分块传输一起使用。
来自输入数据的每个块将被包装在HttpContent内 。 在输入数据的末尾,将写入LastHttpContent 。
确保您的HTTP响应标头包含Transfer-Encoding: chunked 。
public void messageReceived(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
response.headers().set(TRANSFER_ENCODING, CHUNKED);
ctx.write(response);
HttpContentChunkedInput httpChunkWriter = new HttpChunkedInput(
new ChunkedFile("/tmp/myfile.txt"));
ChannelFuture sendFileFuture = ctx.write(httpChunkWriter);
}
| Constructor and Description |
|---|
HttpChunkedInput(ChunkedInput<ByteBuf> input)
使用指定的输入创建一个新实例。
|
HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent)
使用指定的输入创建一个新实例。
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
释放与输入相关的资源。
|
boolean |
isEndOfInput()
返回
true当且仅当数据流中没有剩余数据且数据流已达到其结尾时。
|
long |
length()
返回输入的长度。
|
long |
progress()
返回当前传输进度。
|
HttpContent |
readChunk(ByteBufAllocator allocator)
从流中获取分块的数据。
|
HttpContent |
readChunk(ChannelHandlerContext ctx)
已过时。
|
public HttpChunkedInput(ChunkedInput<ByteBuf> input)
input - ChunkedInput包含要写入的数据
public HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent)
lastHttpContent将被写为终止块。
input - ChunkedInput包含要写入的数据
lastHttpContent - LastHttpContent将被写为终止块。
使用它来训练标题。
public boolean isEndOfInput()
throws java.lang.Exception
ChunkedInput
true当且仅当数据流中没有剩余数据并且数据流已达到其结尾时。
isEndOfInput在界面
ChunkedInput<HttpContent>
java.lang.Exception
public void close()
throws java.lang.Exception
ChunkedInput
close在界面
ChunkedInput<HttpContent>
java.lang.Exception
@Deprecated public HttpContent readChunk(ChannelHandlerContext ctx) throws java.lang.Exception
readChunk接口
ChunkedInput<HttpContent>
ctx -它提供了一个上下文ByteBufAllocator如果缓冲区分配是必要的。
null如果流中没有剩余数据。
请注意, null并不一定意味着该流已达到其结尾。
在缓慢的流中,下一个块可能暂时不可用。
java.lang.Exception
public HttpContent readChunk(ByteBufAllocator allocator) throws java.lang.Exception
ChunkedInput
ChunkedInput.isEndOfInput()调用都必须返回true 。
readChunk在界面
ChunkedInput<HttpContent>
allocator - ByteBufAllocator如果缓冲区分配是必要的。
null如果流中没有剩余数据。
请注意, null并不一定意味着该流已到达结尾。
在缓慢的流中,下一个块可能暂时不可用。
java.lang.Exception
public long length()
ChunkedInput
length在界面
ChunkedInput<HttpContent>
public long progress()
ChunkedInput复制的描述
progress在界面
ChunkedInput<HttpContent>
Copyright © 2008–2018 The Netty Project. All rights reserved.