users@grizzly.java.net

Re: Eliminating buffer copy in upload with NIOInputStream

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Tue, 26 Jul 2011 18:26:20 +0200

Hi Jon,

>
> def len = inputStream.readyData()
> def b = new byte[len]
> inputStream.read(b)
> channel.write(ByteBuffer.wrap(b),
> channel.size(), b, handler)
This is one "byte[] copy" worse than getBuffer() approach in the sample
I referred in prev. emails.
Wait a bit, currently I'm working on sample, which is going to use
direct buffers, which avoids any buffer copy.

WBR,
Alexey.

>
> 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
>
>