title: How to send text and binary data from a custom netty HTTP server in Java?
body: <p>Based on netty 3.6 I am implementing a small HTTP server into my Java desktop application. By now I have successfully created the basic HTTP server layout, I can send various text-based files to my browser-based clients.</p>
  
  <p>In my netty server pipeline factory I create new channel pipelines as following:</p>
  
  <pre><code>pipeline.addLast("decoder", new HttpRequestDecoder());
  pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
  pipeline.addLast("encoder", new HttpResponseEncoder());
  pipeline.addLast("handler", new HttpServerHandler());
  </code></pre>
  
  <p>In my <code>HttpServerHandler</code> class I send text data to the clients as following:</p>
  
  <pre><code>HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(CONTENT_TYPE, contentType + "; charset=UTF-8");
  response.setHeader(PRAGMA, "no-cache");
  response.setContent(ChannelBuffers.copiedBuffer(responseText, CharsetUtil.UTF_8));
  
  if(keepAlive)
  {
      response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
      response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
  }
  
  ChannelFuture future = e.getChannel().write(response);
  </code></pre>
  
  <p>Good. Now I additionally want to send binary data (e.g. images) to my clients. Since I found no online example on how to achieve this I have two questions:</p>
  
  <ol>
  <li>How do I need to modify the channel pipeline to be able to send both, text and binary data to my clients?</li>
  <li>How to modify the <code>HttpServerHandler</code> class in order to send a binary file to the client?</li>
  </ol>