users@grizzly.java.net

Eliminating buffer copy in upload with NIOInputStream

From: Jon Brisbin <jon_at_jbrisbin.com>
Date: Tue, 26 Jul 2011 10:13:16 -0500 (CDT)

I'm trying to eliminate a buffer copy in my file upload handling code. I'm currently doing:

def len = inputStream.readyData()
def b = new byte[len]
inputStream.read(b)
channel.write(ByteBuffer.wrap(b), channel.size(), b, handler)

using Java 7's AsynchronousFileChannel. I'd like to be able to shove a ByteBuffer directly into the channel.write() with no copying or anything.

I couldn't find a way to do this that would not incur extra steps nor involve additional allocations of buffers. Is there some low-level slicing I can do or something to eliminate this?


Thanks!

Jon Brisbin
http//jbrisbin.com