public class AisPacketReader extends Object implements AutoCloseable, Iterable<AisPacket>
| Modifier and Type | Field and Description |
|---|---|
protected AisPacketParser |
packetReader
Reader to parse lines and deliver complete AIS packets.
|
| Constructor and Description |
|---|
AisPacketReader(InputStream stream)
Create
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static AisPacketReader |
createFromFile(Path p,
boolean throwExceptions)
Creates a new AIS packet reader from the specified file.
|
static AisPacketReader |
createFromSystemResource(String resourceName,
boolean throwExceptions)
Create from system resource ais packet reader.
|
void |
forEachRemaining(Consumer<? super AisPacket>... consumers)
For each remaining.
|
void |
forEachRemainingMessage(Consumer<? super AisMessage>... consumers)
For each remaining message.
|
long |
getNumberOfBytesRead()
Returns the number of bytes read by this reader.
|
long |
getNumberOfLinesRead()
Returns the number of lines read by this reader.
|
long |
getNumberOfPacketsRead()
Returns the number of packets read by this reader.
|
protected void |
handleAbk(Abk abk)
Override this method to handle
Abk sentences. |
Iterator<AisPacket> |
iterator() |
AisPacket |
readPacket()
Read packet ais packet.
|
AisPacketStream |
stream()
Returns a AIS packet stream running in a new thread.
|
AisPacketStream |
stream(Executor e)
Returns a AIS packet stream using the specified executor.
|
void |
writeTo(OutputStream os,
dk.dma.commons.util.io.OutputStreamSink<AisPacket> sink)
Writes the reminder of packets to the output stream using the specified sink
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorprotected final AisPacketParser packetReader
public AisPacketReader(InputStream stream)
stream - the input stream to read data frompublic void close()
throws IOException
close in interface AutoCloseableIOExceptionpublic long getNumberOfBytesRead()
public long getNumberOfLinesRead()
public long getNumberOfPacketsRead()
protected void handleAbk(Abk abk)
Abk sentences.abk - the sentence to handle@SafeVarargs public final void forEachRemaining(Consumer<? super AisPacket>... consumers) throws IOException
consumers - the consumersIOException - the io exception@SafeVarargs public final void forEachRemainingMessage(Consumer<? super AisMessage>... consumers) throws IOException
consumers - the consumersIOException - the io exceptionpublic AisPacket readPacket() throws IOException
IOException - if an exception occurred while reading the packetpublic AisPacketStream stream()
public AisPacketStream stream(Executor e)
e - the epublic static AisPacketReader createFromSystemResource(String resourceName, boolean throwExceptions) throws IOException
resourceName - the resource namethrowExceptions - the throw exceptionsIOException - the io exceptionpublic static AisPacketReader createFromFile(Path p, boolean throwExceptions) throws IOException
p - the path of the filethrowExceptions - whether to throw exceptions or just log themIOException - if the reader failed to be constructed, for example, if the specified file does not existpublic void writeTo(OutputStream os, dk.dma.commons.util.io.OutputStreamSink<AisPacket> sink) throws IOException
os - the output stream to write tosink - the sink to write toIOException - if the a packet could not be writtenCopyright © 2011–2019 Danish Maritime Authority. All rights reserved.