PrintWriter writer = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
writer.println("The woods are lovely dark and deep.");
writer.println("But I have promises to keep.");
writer.flush();
writeChannel.waitForOutstandingWrites();
writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes("UTF8")));
writeChannel.close();
resp.getWriter().println("Done writing...");