Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > InputStream and Selector

Reply
Thread Tools

InputStream and Selector

 
 
HK
Guest
Posts: n/a
 
      04-19-2005
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.

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      04-19-2005
On 19 Apr 2005 08:51:30 -0700, HK wrote:
> 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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Harald
Guest
Posts: n/a
 
      04-19-2005
Gordon Beaton <(E-Mail Removed)> writes:

> On 19 Apr 2005 08:51:30 -0700, HK wrote:
>> 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)


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

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

Thanks,
Harald.

--
---------------------+---------------------------------------------
Harald Kirsch (@home)|
Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software
 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      04-21-2005
Harald wrote:

> Gordon Beaton <(E-Mail Removed)> writes:
>
>
>>On 19 Apr 2005 08:51:30 -0700, HK wrote:
>>
>>>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)

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


Unfortunately such a channel is blocking mode only and cannot be used
with a Selector.
 
Reply With Quote
 
Harald Kirsch
Guest
Posts: n/a
 
      04-22-2005
Esmond Pitt <(E-Mail Removed)> wrote in message news:<RPH9e.18506$(E-Mail Removed)>...
> Harald wrote:
>
> > Gordon Beaton <(E-Mail Removed)> writes:
> >
> >
> >>On 19 Apr 2005 08:51:30 -0700, HK wrote:
> >>
> >>>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)

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

>
> 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.
 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      04-23-2005
Harald Kirsch wrote:

> Esmond Pitt <(E-Mail Removed)> wrote in message news:<RPH9e.18506$(E-Mail Removed)>...
>>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?


Yes, that is the bottom line.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class selector, ID selectors and link pseudo-classes Luigi Donatello Asero HTML 4 06-04-2005 05:02 PM
confused: Socket InputStream != ServerSocker InputStream R Java 5 03-13-2005 07:26 AM
Multi list box selector and post back question Brian Henry ASP .Net 3 08-18-2004 11:31 PM
selector.select() in NIO and high cpu usage Arandil Java 1 04-12-2004 02:04 PM
id selector and IE steven HTML 13 01-26-2004 11:47 PM



Advertisments