InputStream and Selector

Discussion in 'Java' started by HK, Apr 19, 2005.

  1. HK

    HK Guest

    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.
    HK, Apr 19, 2005
    #1
    1. Advertising

  2. 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
    Gordon Beaton, Apr 19, 2005
    #2
    1. Advertising

  3. HK

    Harald Guest

    Gordon Beaton <> 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
    Harald, Apr 19, 2005
    #3
  4. HK

    Esmond Pitt Guest

    Harald wrote:

    > Gordon Beaton <> 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.
    Esmond Pitt, Apr 21, 2005
    #4
  5. Esmond Pitt <> wrote in message news:<RPH9e.18506$>...
    > Harald wrote:
    >
    > > Gordon Beaton <> 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.
    Harald Kirsch, Apr 22, 2005
    #5
  6. HK

    Esmond Pitt Guest

    Harald Kirsch wrote:

    > Esmond Pitt <> wrote in message news:<RPH9e.18506$>...
    >>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.
    Esmond Pitt, Apr 23, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry
    Replies:
    3
    Views:
    6,082
  2. Arandil
    Replies:
    1
    Views:
    1,297
    Arandil
    Apr 12, 2004
  3. R
    Replies:
    5
    Views:
    2,101
    Kevin McMurtrie
    Mar 13, 2005
  4. steven

    id selector and IE

    steven, Jan 22, 2004, in forum: HTML
    Replies:
    13
    Views:
    801
    Jeff Thies
    Jan 26, 2004
  5. Luigi Donatello Asero

    Class selector, ID selectors and link pseudo-classes

    Luigi Donatello Asero, Jun 4, 2005, in forum: HTML
    Replies:
    4
    Views:
    506
    Luigi Donatello Asero
    Jun 4, 2005
Loading...

Share This Page