Created
April 3, 2016 19:58
-
-
Save nickman/8ad8f3294deba5f7a371b9bfb4cb7993 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final DefaultFileRegion region = new DefaultFileRegion(file.getChannel(), 0, length); | |
final ByteBuf fb = ctx().alloc().directBuffer((int)length); | |
region.transferTo(new WritableByteChannel(){ | |
@Override | |
public boolean isOpen() { | |
return true; | |
} | |
@Override | |
public void close() throws IOException { /* No Op */} | |
@Override | |
public int write(final ByteBuffer src) throws IOException { | |
final int start = fb.writerIndex(); | |
fb.writeBytes(src); | |
return fb.writerIndex() - start; | |
} | |
}, 0); | |
FullHttpResponse fhr = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, fb); | |
fhr.headers().add(request().headers()); | |
final ChannelFuture future = ctx().writeAndFlush(fhr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment