InputStream and Selector

H

HK

Hi,

is there any way to get a java.io.InputStream
go together with a java.nio.channels.Selector?

What I would like to do is similar to copying
System.in to System.out. Of course I can call
System.in.read() and System.out.write() in
sequence. The problem is: If no input arrives,
the thread will hang around in the read().
During that time, the ouput may be closed
by the other side without the thread
noticing.

Two threads, one for reading, one for
writing seems to be a bit of an overkill.

Harald.
 
G

Gordon Beaton

is there any way to get a java.io.InputStream
go together with a java.nio.channels.Selector?

Create a Channel from the InputStream:

java.nio.channels.newChannel(InputStream)

/gordon
 
H

Harald

Gordon Beaton said:
Create a Channel from the InputStream:

java.nio.channels.newChannel(InputStream)

Almost:
java.nio.channels.Channels.newChannel(InputStream)

Looks like some GPS is needed to find your way around all these
channel maze.-(

Thanks,
Harald.
 
E

Esmond Pitt

Harald said:
Almost:
java.nio.channels.Channels.newChannel(InputStream)

Unfortunately such a channel is blocking mode only and cannot be used
with a Selector.
 
H

Harald Kirsch

Esmond Pitt said:
Unfortunately such a channel is blocking mode only and cannot be used
with a Selector.

Does this mean the bottom line is: System.in can not ever be
used with a Selector?

Harald.
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top