Skip to content

Instantly share code, notes, and snippets.

View sigbjod's full-sized avatar

Sigbjørn Dybdahl sigbjod

  • Paris, France
View GitHub Profile
@sigbjod
sigbjod / HttpGetRequestHandler.java
Created September 23, 2013 17:43
java.io.IOException caught while using a RandomAccessFile object for the 2nd time in Netty
private void finish(ChannelHandlerContext channel, HttpResponse response,
RandomAccessFile gif, String contentType) {
ChannelFuture future = null;
try {
long fileLength = gif.length();
response.headers().set(CONTENT_LENGTH, fileLength);
response.headers().set(CONTENT_TYPE, contentType);
future = channel.write(response);
DefaultFileRegion region = new DefaultFileRegion(gif.getChannel(), 0,
@sigbjod
sigbjod / HttpPipelineFactory.java
Last active February 1, 2018 08:46
My implementation of a Netty server handling HTTP requests
public class HttpPipelineFactory implements ChannelPipelineFactory {
private final ExecutionHandler executionHandler;
private final ProductDaoImpl productDao;
public HttpPipelineFactory(ProductDaoImpl productDao,
OrderedMemoryAwareThreadPoolExecutor eventExecutor) {
this.productDao = productDao;
this.executionHandler = new ExecutionHandler(eventExecutor);
}