Chris Mowforth
Chris Mowforth

Reputation: 6723

Is there an equivalent to transferTo for AsynchronousFileChannel?

I've been playing around with NIO2 in Java 7 and I kind of assumed that the AsynchronousFileChannel would have a transferTo method like its synchronous FileChannel sibling.

I'm looking to perform a zero-copy transfer between a local file and an open TCP socket. I've tried to simply create a FileChannel and call transferTo with my AsynchronousSocketChannel as the last arg but in seeing as the async socket version isn't a WritableByteChannel, Java won't have it.

With that ruled out as an option, does anybody know of a workaround or external library that would allow me to pipe bytes to an AsynchronousSocketChannel leveraging DMA (and by implication using no buffers in user-space)?

Upvotes: 3

Views: 1047

Answers (1)

user207421
user207421

Reputation: 310884

transferTo() isn't an asynchronous operation. So performing it on an asynchronous channel makes no sense. So it isn't provided.

Upvotes: 1

Related Questions