com.partnersoft.io
Class SlowLineReader

java.lang.Object
  extended by com.partnersoft.io.SlowLineReader

public class SlowLineReader
extends java.lang.Object

Reads complete lines from an InputStream. This is designed not to block if the input stream is reading from a slow source like a serial port.

Author:
Russell Cagle Copyright 2007 Partner Software, Inc.

Constructor Summary
SlowLineReader(java.io.InputStream in)
           
 
Method Summary
 void close()
           
 java.lang.StringBuffer getLastRead()
          Returns the new bytes we found in the last call to readLine().
 java.lang.String readLine()
           Returns null if it can't read a complete line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlowLineReader

public SlowLineReader(java.io.InputStream in)
Method Detail

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getLastRead

public java.lang.StringBuffer getLastRead()
Returns the new bytes we found in the last call to readLine().

Returns:

readLine

public java.lang.String readLine()
                          throws java.io.IOException

Returns null if it can't read a complete line. Internally, this function stops reading if it reaches the end of a complete line or if the next read would block.

If there baud rate is set incorrectly or there is too much line noise, there is never a complete line, and the accumulation buffer overflows. To counter that, this function gives up looking for a complete line and returns what is has read if the accumulated partial line is longer than 160 characters, which is twice the length of a normal NMEA line.

Returns:
Throws:
java.io.IOException