Results 1 to 4 of 4
- 07-18-2007, 02:14 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
Un expected behaviour when reading from inputstream
sir,
we all know that when we read from an inputstream using read()
method of the InputStream class,it should return -1 when end of the
stream reaches.
In my case when I try to read from the InputStream of a serial port,it
blocks instead of returning -1 (when reaches end of stream) and returns the
data when it available.
Do any one know the answer,please help me.
thanks in advance,
Adoorsarath
- 07-18-2007, 04:25 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 33
- Rep Power
- 0
Can you write the code?
- 07-19-2007, 06:32 AM #3
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
Code is given below
description:Java Code:class ModemReader extends Thread { InputStream in=SimpleSMSReader.inputStream; int c; public void run() { [INDENT][/INDENT]try { [INDENT][INDENT][/INDENT][/INDENT]while(true) { if(SimpleSMSReader.readMessage==true) { c=in.read(); while (c != -1) { queue.put((byte) c); c = in.read(); } SimpleSMSReader.readMessage=false; //Here i have to write some code to parse the message. // ie.. only after reading the whole data available. //but in this case it is not exiting from the loop instead // it waits for another data availability.and reads when // data available. } } }catch(Exception e) { System.out.println(e.toString()); } } }
When some data is available in the inputStream,the static variable readMessage in the class SimpleSMSReader is set to True.Last edited by JavaBean; 07-19-2007 at 07:08 AM.
- 08-10-2007, 05:02 PM #4
Senior Member
- Join Date
- Jun 2007
- Posts
- 164
- Rep Power
- 6
Similar Threads
-
Converting InputStream to OutputStream
By Java Tip in forum Java TipReplies: 1Last Post: 01-11-2008, 10:13 PM -
Reading form inputStream and storing in ByteArray
By Java Tip in forum Java TipReplies: 0Last Post: 11-27-2007, 10:23 AM -
Reading bytes from InputStream
By Java Tip in forum Java TipReplies: 0Last Post: 11-25-2007, 07:51 PM -
Error: ')' expected
By baltimore in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:32 AM -
Error: '{' expected
By romina in forum New To JavaReplies: 1Last Post: 07-26-2007, 09:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks