### Question:
FileTransfer implements WritableMessage { @Override public int remaining() { return len > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) len; } FileTransfer(final File f);  FileTransfer(final File f, final long pos, final long len); long writeTo(final WritableByteChannel c); @Override boolean hasRemaining(); @Override int remaining(); @Override boolean release(); @Override boolean isExternal();  }### Answer:
@Test public void testSimpleFileTransfer() throws Exception { TCPNIOTransport t = TCPNIOTransportBuilder.newInstance().build(); FilterChainBuilder builder = FilterChainBuilder.stateless(); final File f = generateTempFile(1024 * 1024); builder.add(new TransportFilter()); builder.add(new BaseFilter() { @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { ctx.write(new FileTransfer(f)); return ctx.getStopAction(); } }); t.setProcessor(builder.build()); t.bind(PORT); t.start(); TCPNIOTransport client = TCPNIOTransportBuilder.newInstance().build(); FilterChainBuilder clientChain = FilterChainBuilder.stateless(); final SafeFutureImpl<File> future = SafeFutureImpl.create(); final File temp = File.createTempFile("grizzly-download-", ".tmp"); temp.deleteOnExit(); final FileOutputStream out = new FileOutputStream(temp); final AtomicInteger total = new AtomicInteger(0); clientChain.add(new TransportFilter()); clientChain.add(new BaseFilter() { @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { ctx.write(Buffers.wrap(MemoryManager.DEFAULT_MEMORY_MANAGER, ".")); return ctx.getStopAction(); } @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Buffer b = ctx.getMessage(); ByteBuffer bb = b.toByteBuffer(); total.addAndGet(b.remaining()); out.getChannel().write(bb); if (total.get() == f.length()) { future.result(temp); } return ctx.getStopAction(); } }); client.setProcessor(clientChain.build()); client.start(); client.connect("localhost", PORT); long start = System.currentTimeMillis(); BigInteger testSum = getMDSum(future.get(10, TimeUnit.SECONDS)); long stop = System.currentTimeMillis(); BigInteger controlSum = getMDSum(f); assertTrue(controlSum.equals(testSum)); System.out.println("File transfer completed in " + (stop - start) + " ms."); }