Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Nonblocking System.in.read(...) ?

800308Jan 3 2009 — edited Jan 5 2009
Folks,

Question: Please, does anyone know: How to open a Channel on a given BufferedInputStream? Is it possible?

Background: I've spent my morning trying to knutt-out how to read bytes from System.in (an InputStream which is-a BufferedInputStream) without blocking if there are no bytes immediately available to read.

I thought the New IO package ([java.nio|http://java.sun.com/javase/6/docs/api/java/nio/package-summary.html]) would enable this... but if it does then I, for the life of me, can't figure out how. NIO's API doco is rather circular, and I ended up just going round in circles for the couple of hours.... Very, very frusterpating!!!

[The articles on NIO|http://www.google.com/search?q=java+nio&hl=en&sourceid=gd&rls=GGLD,GGLD:2008-06,GGLD:en&aq=t] all (well, atleast those I've found so far) discuss non-blocking socket-io... which was a core motivation for the package (towards reducing threading overhead in J2EE servers). [This one|http://rox-xmlrpc.sourceforge.net/niotut/] by James Greenfield (Esquire) is the most readable I've found to date... with references! Wow!

At this stage of the game, I'd be ecstatic with any solution... threaded or not, dead-threading or not, actually or logically locking interupted, closed or unclosed, unclean messy hack or bright shining beautiful boy... just so long as it doesn't block reading stdin.

Cheers all. Keith.

-----
Edited by: corlettk on 4/01/2009 13:13 Forgot to mention that I'm running 1.6.0_07 on Windows Vista (sucks) Pro... this is/was all a lot easier in C on unix ;-)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2009
Added on Jan 3 2009
7 comments
4,083 views