making a ByteChannel from a ByteBuffer?

B

bugbear

In the java.io code set, it's easy to take
a "pile o' data", and put a facade over it
so it looks like a data source.

byte [] stuff;
java.io.InputStream inputStream = new java.io.ByteArrayInputStream(stuff);

In the new and improved world of nio, I would like
(analogously) to present a java.nio.ByteBuffer as a
java.nio.ReadableByteChannel (*).

I cannot find (I've looked **) an obvious way to do this.
Can anyone help?

BugBear

(*) If anyone cares, I actually *need* to present a ByteBuffer
as an InputStream, but the java.nio.channels.Channels
has implements

static InputStream newInputStream(ReadableByteChannel ch)

(**) i.e. I've read and reread the javadoc for java.nio, and googled
a lot.
 
M

Mart?n.

I don´t know if I understand what you're trying to do, but maybe it is:

byte [] stuff;
ByteArrayInputStream inputStream = new ByteArrayInputStream(stuff);
ReadableByteChannel c = Channels.newChannel(inputStream);

Martín.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top