Netty等价于getOutputStream()

Netty等价于getOutputStream(),netty,Netty,我已经在Netty中编写了一个上传文件的服务器,但是我没有成功地实现java中的response.getOutputStream()。 知道我有一个ChannelHandlerContext对象和一个DefaultFullHttpRequest对象,我该怎么办 这是我的密码: @覆盖 public void channelRead0(最终ChannelHandlerContext chctx,最终DefaultFullHttpRequest对象) 抛出异常{ //检索内容 ByteBuf dat

我已经在Netty中编写了一个上传文件的服务器,但是我没有成功地实现java中的
response.getOutputStream()
。 知道我有一个
ChannelHandlerContext
对象和一个
DefaultFullHttpRequest
对象,我该怎么办

这是我的密码:

@覆盖
public void channelRead0(最终ChannelHandlerContext chctx,最终DefaultFullHttpRequest对象)
抛出异常{
//检索内容
ByteBuf data=object.content();
if(HttpMethod.POST.equals(object.getMethod())){
/*while(data.isReadable()){
output.write(data.readByte());
}*/
int dataLen=data.readableBytes();
ByteBuffer数据;
if(data.niobffercount()!=-1){
nioData=data.nioBuffer();
}否则{
nioData=ByteBuffer.allocate(dataLen);
data.getBytes(data.readerIndex(),nioData);
nioData.flip();//输入流
}
/*FileChannel chan=outputStream.getChannel();
写(数据);
chan.transferFrom(chctx.write,0,dataLen)*/
//chctx.写入(数据);
}
}

您可以使用ByteBuf的方法
readBytes(OutputStream out,int length)
将http请求汇总的数据写入FileOutputStream:

...
OutputStream out = new FileOutputStream("someFile");
nioData.readBytes(out,  nioData.readableBytes());
...