Results 1 to 4 of 4
  1. #1
    adoorsarath is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    cecily is offline Member
    Join Date
    Jul 2007
    Posts
    33
    Rep Power
    0

    Default

    Can you write the code?

  3. #3
    adoorsarath is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default Code is given below

    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());
                }
        }
    
    }
    description:

    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.

  4. #4
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    7

Similar Threads

  1. Converting InputStream to OutputStream
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-11-2008, 10:13 PM
  2. Replies: 0
    Last Post: 11-27-2007, 10:23 AM
  3. Reading bytes from InputStream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-25-2007, 07:51 PM
  4. Error: ')' expected
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:32 AM
  5. Error: '{' expected
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-26-2007, 09:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •