Google Answers Logo
View Question
 
Q: How to determine if a Java InputStream has data to be read ( No Answer,   2 Comments )
Question  
Subject: How to determine if a Java InputStream has data to be read
Category: Computers
Asked by: integragreg-ga
List Price: $10.00
Posted: 16 Dec 2002 17:55 PST
Expires: 15 Jan 2003 17:55 PST
Question ID: 125721
How do I determine if a Java InputStream has data that is available to
be read without checking the return value of the available() method
based on a timer?
Answer  
There is no answer at this time.

Comments  
Subject: Re: How to determine if a Java InputStream has data to be read
From: billphipps-ga on 16 Dec 2002 18:48 PST
 
Hi integragreg-ga,

Your best bet is to create a new thread that blocks on the
InputStream.read() function.  This thread will become asynchonously
and automatically unblocked once there is data available.  You can
handle the incoming data in that new thread or synchronize back with
your main program once the data is available.  Of course, it all
depends on what you are doing with the data...

Check the javasoft docs at 

http://java.sun.com/j2se/1.4.1/docs/api/java/io/InputStream.html#read()

for more information about the read() function.

If you want some sample source, give a holler. :)

Good luck,
Bill
Subject: Re: How to determine if a Java InputStream has data to be read
From: integragreg-ga on 17 Dec 2002 06:14 PST
 
Hey Bill,

Thanks for the response.  I would greatly appreciate a code snippet if
you have time.  I am developing a class that connects to a remote host
and needs to asynchronously unblock as you suggest.

Just FYI, once data is received on the InputStream, I am going to
remove a 32-bit header and pass the remaining bytes in the inputstream
up to another class for processing.  FWIW, I am implementing RFC 1006
in Java.

Cheers,

Greg

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy