aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/LocalStorage.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2013-09-14 14:17:56 +0200
committerSamuel Tardieu <sam@rfc1149.net>2013-09-14 14:17:56 +0200
commit3d5d4c46327244244003982f71aa627d1407d5c3 (patch)
tree8b8fa0f0d95108cee03257f53bbb2b84350a17ce /main/src/cgeo/geocaching/files/LocalStorage.java
parent371f6e7fe5bfc68fb208374ca108893a14b44100 (diff)
downloadcgeo-3d5d4c46327244244003982f71aa627d1407d5c3.zip
cgeo-3d5d4c46327244244003982f71aa627d1407d5c3.tar.gz
cgeo-3d5d4c46327244244003982f71aa627d1407d5c3.tar.bz2
refactoring: do not use default encoding
For headers and mount point parsing, we use UTF-8, which is almost certainly the default on the platform, even if only the ASCII plane is likely to be used.
Diffstat (limited to 'main/src/cgeo/geocaching/files/LocalStorage.java')
-rw-r--r--main/src/cgeo/geocaching/files/LocalStorage.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java
index 05713cc..e5ba8c0 100644
--- a/main/src/cgeo/geocaching/files/LocalStorage.java
+++ b/main/src/cgeo/geocaching/files/LocalStorage.java
@@ -8,7 +8,6 @@ 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;
@@ -21,11 +20,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;
@@ -204,7 +205,13 @@ public final class LocalStorage {
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);
+ }
}
}
@@ -224,7 +231,7 @@ public final class LocalStorage {
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];
@@ -410,10 +417,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) {