aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-05-11 08:56:34 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-05-11 09:34:58 +0200
commitaea41c86f05d11828120fa71c0bcb5b1756061f1 (patch)
treeb2bb0ee0c681a838e1c22eb61885e2c1a5ca715e /main/src/cgeo/geocaching/files
parentf3b65c3221d96bd431000b71bc8fb29a81c0eab9 (diff)
downloadcgeo-aea41c86f05d11828120fa71c0bcb5b1756061f1.zip
cgeo-aea41c86f05d11828120fa71c0bcb5b1756061f1.tar.gz
cgeo-aea41c86f05d11828120fa71c0bcb5b1756061f1.tar.bz2
#1348: use buffered io
Diffstat (limited to 'main/src/cgeo/geocaching/files')
-rw-r--r--main/src/cgeo/geocaching/files/FileParser.java12
-rw-r--r--main/src/cgeo/geocaching/files/GPXImporter.java5
-rw-r--r--main/src/cgeo/geocaching/files/LocalStorage.java19
3 files changed, 19 insertions, 17 deletions
diff --git a/main/src/cgeo/geocaching/files/FileParser.java b/main/src/cgeo/geocaching/files/FileParser.java
index 50b65a1..f979d74 100644
--- a/main/src/cgeo/geocaching/files/FileParser.java
+++ b/main/src/cgeo/geocaching/files/FileParser.java
@@ -2,7 +2,9 @@ package cgeo.geocaching.files;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.IOUtils;
+import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -16,7 +18,7 @@ import java.util.concurrent.CancellationException;
public abstract class FileParser {
/**
* Parses caches from input stream.
- *
+ *
* @param stream
* @param progressHandler
* for reporting parsing progress (in bytes read from input stream)
@@ -38,11 +40,11 @@ public abstract class FileParser {
* @throws ParserException
*/
public Collection<Geocache> parse(final File file, final CancellableHandler progressHandler) throws IOException, ParserException {
- FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file));
try {
- return parse(fis, progressHandler);
+ return parse(stream, progressHandler);
} finally {
- fis.close();
+ IOUtils.closeQuietly(stream);
}
}
@@ -59,7 +61,7 @@ public abstract class FileParser {
}
return buffer;
} finally {
- input.close();
+ IOUtils.closeQuietly(input);
}
}
diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java
index ff81fe1..69d2dac 100644
--- a/main/src/cgeo/geocaching/files/GPXImporter.java
+++ b/main/src/cgeo/geocaching/files/GPXImporter.java
@@ -24,6 +24,7 @@ import android.net.Uri;
import android.os.Handler;
import android.os.Message;
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -287,7 +288,7 @@ public class GPXImporter {
Collection<Geocache> caches = Collections.emptySet();
// can't assume that GPX file comes before waypoint file in zip -> so we need two passes
// 1. parse GPX files
- ZipInputStream zis = new ZipInputStream(getInputStream());
+ ZipInputStream zis = new ZipInputStream(new BufferedInputStream(getInputStream()));
try {
for (ZipEntry zipEntry = zis.getNextEntry(); zipEntry != null; zipEntry = zis.getNextEntry()) {
if (StringUtils.endsWithIgnoreCase(zipEntry.getName(), GPX_FILE_EXTENSION)) {
@@ -305,7 +306,7 @@ public class GPXImporter {
}
// 2. parse waypoint files
- zis = new ZipInputStream(getInputStream());
+ zis = new ZipInputStream(new BufferedInputStream(getInputStream()));
try {
for (ZipEntry zipEntry = zis.getNextEntry(); zipEntry != null; zipEntry = zis.getNextEntry()) {
if (StringUtils.endsWithIgnoreCase(zipEntry.getName(), WAYPOINTS_FILE_SUFFIX_AND_EXTENSION)) {
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java
index f59f15c..0f3e0e1 100644
--- a/main/src/cgeo/geocaching/files/LocalStorage.java
+++ b/main/src/cgeo/geocaching/files/LocalStorage.java
@@ -2,14 +2,18 @@ package cgeo.geocaching.files;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.utils.CryptUtils;
+import cgeo.geocaching.utils.IOUtils;
import cgeo.geocaching.utils.Log;
import ch.boye.httpclientandroidlib.Header;
import ch.boye.httpclientandroidlib.HttpResponse;
+
import org.apache.commons.lang3.StringUtils;
import android.os.Environment;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -275,19 +279,14 @@ public class LocalStorage {
destination.getParentFile().mkdirs();
InputStream input = null;
- OutputStream output;
+ OutputStream output = null;
try {
- input = new FileInputStream(source);
- output = new FileOutputStream(destination);
+ input = new BufferedInputStream(new FileInputStream(source));
+ output = new BufferedOutputStream(new FileOutputStream(destination));
} catch (FileNotFoundException e) {
Log.e("LocalStorage.copy: could not open file", e);
- if (input != null) {
- try {
- input.close();
- } catch (IOException e1) {
- // ignore
- }
- }
+ IOUtils.closeQuietly(input);
+ IOUtils.closeQuietly(output);
return false;
}