aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/LocalStorage.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/files/LocalStorage.java')
-rw-r--r--main/src/cgeo/geocaching/files/LocalStorage.java31
1 files changed, 20 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java
index de1908d..40684f8 100644
--- a/main/src/cgeo/geocaching/files/LocalStorage.java
+++ b/main/src/cgeo/geocaching/files/LocalStorage.java
@@ -1,15 +1,15 @@
package cgeo.geocaching.files;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.utils.CryptUtils;
import cgeo.geocaching.utils.FileUtils;
-import cgeo.geocaching.utils.IOUtils;
import cgeo.geocaching.utils.Log;
import ch.boye.httpclientandroidlib.Header;
import ch.boye.httpclientandroidlib.HttpResponse;
-
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jdt.annotation.Nullable;
import android.os.Environment;
@@ -21,11 +21,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -86,7 +88,7 @@ public final class LocalStorage {
private static File getInternalStorageBase() {
if (internalStorageBase == null) {
// A race condition will do no harm as the operation is idempotent. No need to synchronize.
- internalStorageBase = cgeoapplication.getInstance().getApplicationContext().getFilesDir().getParentFile();
+ internalStorageBase = CgeoApplication.getInstance().getApplicationContext().getFilesDir().getParentFile();
}
return internalStorageBase;
}
@@ -205,13 +207,19 @@ public final class LocalStorage {
return false;
}
- private static void saveHeader(final String name, final HttpResponse response, final File baseFile) {
+ private static void saveHeader(final String name, @Nullable final HttpResponse response, final File baseFile) {
final Header header = response != null ? response.getFirstHeader(name) : null;
final File file = filenameForHeader(baseFile, name);
if (header == null) {
FileUtils.deleteIgnoringFailure(file);
} else {
- saveToFile(new ByteArrayInputStream(header.getValue().getBytes()), file);
+ try {
+ saveToFile(new ByteArrayInputStream(header.getValue().getBytes("UTF-8")), file);
+ } catch (final UnsupportedEncodingException e) {
+ // Do not try to display the header in the log message, as our default encoding is
+ // likely to be UTF-8 and it will fail as well.
+ Log.e("LocalStorage.saveHeader: unable to decode header", e);
+ }
}
}
@@ -226,12 +234,13 @@ public final class LocalStorage {
* the name of the cached resource
* @param name
* the name of the header ("etag" or "last-modified")
- * @return null if no value has been cached, the value otherwise
+ * @return the cached value, or <tt>null</tt> if none has been cached
*/
+ @Nullable
public static String getSavedHeader(final File baseFile, final String name) {
try {
final File file = filenameForHeader(baseFile, name);
- final FileReader f = new FileReader(file);
+ final Reader f = new InputStreamReader(new FileInputStream(file), "UTF-8");
try {
// No header will be more than 256 bytes
final char[] value = new char[256];
@@ -417,10 +426,10 @@ public final class LocalStorage {
storages.add(new File(extStorage));
File file = new File("/system/etc/vold.fstab");
if (file.canRead()) {
- FileReader fr = null;
+ Reader fr = null;
BufferedReader br = null;
try {
- fr = new FileReader(file);
+ fr = new InputStreamReader(new FileInputStream(file), "UTF-8");
br = new BufferedReader(fr);
String s = br.readLine();
while (s != null) {