首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Netty 4 HttpContentCompressor文件区域

Netty 4 HttpContentCompressor文件区域
EN

Stack Overflow用户
提问于 2018-03-08 06:24:10
回答 1查看 126关注 0票数 0

我正在尝试发送一个文件到响应和支持编码。代码主要是从Netty github中的一个示例复制而来的。

代码语言:javascript
复制
        ChannelFuture flushFuture;
        if (context.pipeline().get(SslHandler.class) == null) {
            // SSL not enabled - can use zero-copy file transfer.
            context.write(new DefaultFileRegion(raf.getChannel(), 0, getLength()), context.newProgressivePromise());
            flushFuture = context.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
        } else {
            // SSL enabled - cannot use zero-copy file transfer.
            try {
                // HttpChunkedInput will write the end marker (LastHttpContent) for us.
                flushFuture = context.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, getLength(), 8192)),
                        context.newProgressivePromise());
            } catch (IOException e) {
                throw new CustomizableResponseTypeException("Could not read file", e);
            }
        }

当服务器使用SSL时,一切工作正常。当没有使用SSL时,零拷贝文件传输正在进行,编码不会产生正确的输出。

我已经准备好了这个blog post,它似乎表明我正在尝试做的事情可以工作,但是我不明白示例代码的哪一部分可以使它工作。任何提示或帮助都将不胜感激。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-03-09 00:55:07

这似乎是不可能的。解决方案是仅对较小或不可压缩的文件使用零拷贝。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49162206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档