use of org.vesalainen.parsers.nmea.ais.AISContext in project NMEAParser by tvesalainen.
the class NMEAParser method parse.
public <I> void parse(I input, GPSClock gpsClock, Supplier origin, NMEAObserver data, AISObserver aisData) throws IOException {
NMEAChecksum checksum = getChecksum();
checksum.reset();
if (data == null) {
data = new AbstractNMEAObserver();
}
data.start(null);
data.setClock(gpsClock);
gpsClock.start(null);
data.commit("Set clock");
AISContext aisContext = null;
if (aisData != null) {
aisData.start(null);
aisData.setClock(gpsClock);
aisData.commit("Set clock");
aisContext = new AISContext(aisData);
}
try {
if (input instanceof ScatteringByteChannel) {
ScatteringByteChannel sbc = (ScatteringByteChannel) input;
parse(sbc, gpsClock, origin, data, aisContext);
} else {
if (input instanceof URL) {
URL url = (URL) input;
parse(url, gpsClock, origin, data, aisContext);
} else {
if (input instanceof String) {
String str = (String) input;
parse(str, gpsClock, origin, data, aisContext);
} else {
if (input instanceof InputStream) {
InputStream is = (InputStream) input;
parse(is, gpsClock, origin, data, aisContext);
} else {
throw new UnsupportedOperationException(input + " not supported as input");
}
}
}
}
} finally {
if (aisContext != null) {
aisContext.waitAndStopThreads();
}
}
}
Aggregations