aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/files/FileParser.java8
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java4
-rw-r--r--main/src/cgeo/geocaching/files/LocParser.java8
3 files changed, 14 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/files/FileParser.java b/main/src/cgeo/geocaching/files/FileParser.java
index 396a589..973e65f 100644
--- a/main/src/cgeo/geocaching/files/FileParser.java
+++ b/main/src/cgeo/geocaching/files/FileParser.java
@@ -4,6 +4,8 @@ import cgeo.geocaching.Geocache;
import cgeo.geocaching.utils.CancellableHandler;
import org.apache.commons.io.IOUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
@@ -29,7 +31,7 @@ public abstract class FileParser {
* @throws ParserException
* if the input stream contains data not matching the file format of the parser
*/
- public abstract Collection<Geocache> parse(final InputStream stream, final CancellableHandler progressHandler) throws IOException, ParserException;
+ public abstract Collection<Geocache> parse(@NonNull final InputStream stream, @Nullable final CancellableHandler progressHandler) throws IOException, ParserException;
/**
* Convenience method for parsing a file.
@@ -49,7 +51,7 @@ public abstract class FileParser {
}
}
- protected static StringBuilder readStream(InputStream is, CancellableHandler progressHandler) throws IOException {
+ protected static StringBuilder readStream(@NonNull final InputStream is, @Nullable final CancellableHandler progressHandler) throws IOException {
final StringBuilder buffer = new StringBuilder();
ProgressInputStream progressInputStream = new ProgressInputStream(is);
final BufferedReader input = new BufferedReader(new InputStreamReader(progressInputStream, "UTF-8"));
@@ -66,7 +68,7 @@ public abstract class FileParser {
}
}
- protected static void showProgressMessage(final CancellableHandler handler, final int bytesRead) {
+ protected static void showProgressMessage(@Nullable final CancellableHandler handler, final int bytesRead) {
if (handler != null) {
if (handler.isCancelled()) {
throw new CancellationException();
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index 6161088..f3cd326 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -25,6 +25,8 @@ import cgeo.geocaching.utils.SynchronizedDateFormat;
import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -270,7 +272,7 @@ public abstract class GPXParser extends FileParser {
}
@Override
- public Collection<Geocache> parse(final InputStream stream, final CancellableHandler progressHandler) throws IOException, ParserException {
+ public Collection<Geocache> parse(@NonNull final InputStream stream, @Nullable final CancellableHandler progressHandler) throws IOException, ParserException {
resetCache();
final RootElement root = new RootElement(namespace, "gpx");
final Element waypoint = root.getChild(namespace, "wpt");
diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java
index 304b472..223fb5a 100644
--- a/main/src/cgeo/geocaching/files/LocParser.java
+++ b/main/src/cgeo/geocaching/files/LocParser.java
@@ -12,6 +12,8 @@ import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.MatcherWrapper;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
@@ -116,7 +118,7 @@ public final class LocParser extends FileParser {
}
@Override
- public Collection<Geocache> parse(InputStream stream, CancellableHandler progressHandler) throws IOException, ParserException {
+ public Collection<Geocache> parse(@NonNull final InputStream stream, @Nullable final CancellableHandler progressHandler) throws IOException, ParserException {
final String streamContent = readStream(stream, null).toString();
final int maxSize = streamContent.length();
final Map<String, Geocache> coords = parseCoordinates(streamContent);
@@ -136,7 +138,9 @@ public final class LocParser extends FileParser {
cache.setListId(listId);
cache.setDetailed(true);
cache.store(null);
- progressHandler.sendMessage(progressHandler.obtainMessage(0, maxSize * caches.size() / coords.size(), 0));
+ if (progressHandler != null) {
+ progressHandler.sendMessage(progressHandler.obtainMessage(0, maxSize * caches.size() / coords.size(), 0));
+ }
}
Log.i("Caches found in .loc file: " + caches.size());
return caches;