net.sf.marineapi.nmea.io
Class SentenceReader

java.lang.Object
  extended by net.sf.marineapi.nmea.io.SentenceReader

public class SentenceReader
extends Object

Sentence reader detects supported NMEA 0183 sentences from the specified data source and dispatches them to registered listeners as sentence events. Each event contains a parser for the read sentence.

Parsers dispatched by reader are created using SentenceFactory class, where you can also register your own custom parsers.

Author:
Kimmo Tuukkanen
See Also:
AbstractSentenceListener, SentenceListener, SentenceEvent, SentenceFactory

Field Summary
static int DEFAULT_TIMEOUT
          Default timeout value in milliseconds.
 
Constructor Summary
SentenceReader(DatagramSocket source)
          Creates a SentenceReader for UDP/DatagramSocket.
SentenceReader(InputStream source)
          Creates a new instance of SentenceReader.
 
Method Summary
 void addSentenceListener(SentenceListener listener)
          Adds a SentenceListener that wants to receive all sentences read by the reader.
 void addSentenceListener(SentenceListener sl, SentenceId type)
          Adds a SentenceListener that is interested in receiving only sentences of certain type.
 void addSentenceListener(SentenceListener sl, String type)
          Adds a SentenceListener that is interested in receiving only sentences of certain type.
 net.sf.marineapi.nmea.io.ExceptionListener getExceptionListener()
          Returns the exception call-back listener.
 int getPauseTimeout()
          Returns the current reading paused timeout.
 void removeSentenceListener(SentenceListener listener)
          Remove a listener from reader.
 void setDatagramSocket(DatagramSocket socket)
          Sets the DatagramSocket to be used as data source.
 void setExceptionListener(net.sf.marineapi.nmea.io.ExceptionListener exceptionListener)
          Set exception call-back listener.
 void setInputStream(InputStream stream)
          Sets the InputStream to be used as data source.
 void setPauseTimeout(int millis)
          Set timeout time for reading paused events.
 void start()
          Starts reading the input stream and dispatching events.
 void stop()
          Stops the reader and event dispatching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
Default timeout value in milliseconds.

See Also:
Constant Field Values
Constructor Detail

SentenceReader

public SentenceReader(DatagramSocket source)
Creates a SentenceReader for UDP/DatagramSocket.

Parameters:
source - Socket from which to read NMEA data

SentenceReader

public SentenceReader(InputStream source)
Creates a new instance of SentenceReader.

Parameters:
source - Stream from which to read NMEA data
Method Detail

addSentenceListener

public void addSentenceListener(SentenceListener listener)
Adds a SentenceListener that wants to receive all sentences read by the reader.

Parameters:
listener - SentenceListener to be registered.
See Also:
SentenceListener

addSentenceListener

public void addSentenceListener(SentenceListener sl,
                                SentenceId type)
Adds a SentenceListener that is interested in receiving only sentences of certain type.

Parameters:
sl - SentenceListener to add
type - Sentence type for which the listener is registered.
See Also:
SentenceListener

addSentenceListener

public void addSentenceListener(SentenceListener sl,
                                String type)
Adds a SentenceListener that is interested in receiving only sentences of certain type.

Parameters:
sl - SentenceListener to add
type - Sentence type for which the listener is registered.
See Also:
SentenceListener

getExceptionListener

public net.sf.marineapi.nmea.io.ExceptionListener getExceptionListener()
Returns the exception call-back listener.

Returns:
Currently set ExceptionListener, or null if none.

getPauseTimeout

public int getPauseTimeout()
Returns the current reading paused timeout.

Returns:
Timeout limit in milliseconds.
See Also:
setPauseTimeout(int)

removeSentenceListener

public void removeSentenceListener(SentenceListener listener)
Remove a listener from reader. When removed, listener will not receive any events from the reader.

Parameters:
listener - SentenceListener to be removed.

setDatagramSocket

public void setDatagramSocket(DatagramSocket socket)
Sets the DatagramSocket to be used as data source. If reader is running, it is first stopped and you must call start() to resume reading.

Parameters:
socket - DatagramSocket to set

setExceptionListener

public void setExceptionListener(net.sf.marineapi.nmea.io.ExceptionListener exceptionListener)
Set exception call-back listener.

Parameters:
exceptionListener - Listener to set, or null to reset.

setInputStream

public void setInputStream(InputStream stream)
Sets the InputStream to be used as data source. If reader is running, it is first stopped and you must call start() to resume reading.

Parameters:
stream - InputStream to set.

setPauseTimeout

public void setPauseTimeout(int millis)
Set timeout time for reading paused events. Default is 5000 ms.

Parameters:
millis - Timeout in milliseconds.

start

public void start()
Starts reading the input stream and dispatching events.

Throws:
IllegalStateException - If reader is already running.

stop

public void stop()
Stops the reader and event dispatching.



Copyright (C) 2010-2014 Java Marine API authors. All Rights Reserved.