diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2014-09-07 19:13:53 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2014-09-07 19:13:53 +0200 |
| commit | d43489275c228fa839464564d94f1f003b0475f6 (patch) | |
| tree | 36d6c484f5a9ba6e8e895cbea89f95d8e8bdcfa0 | |
| parent | 27c430e5e616d706d8a2a23d0709219fe35b3e77 (diff) | |
| download | cgeo-d43489275c228fa839464564d94f1f003b0475f6.zip cgeo-d43489275c228fa839464564d94f1f003b0475f6.tar.gz cgeo-d43489275c228fa839464564d94f1f003b0475f6.tar.bz2 | |
findbugs: use explicit encoding
| -rw-r--r-- | main/src/cgeo/geocaching/files/FileParser.java | 9 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/FileTypeDetector.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocalStorage.java | 36 |
3 files changed, 30 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/files/FileParser.java b/main/src/cgeo/geocaching/files/FileParser.java index 973e65f..9521c70 100644 --- a/main/src/cgeo/geocaching/files/FileParser.java +++ b/main/src/cgeo/geocaching/files/FileParser.java @@ -4,6 +4,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.utils.CancellableHandler; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.CharEncoding; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -43,7 +44,7 @@ public abstract class FileParser { * @throws ParserException */ public Collection<Geocache> parse(final File file, final CancellableHandler progressHandler) throws IOException, ParserException { - BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); + final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); try { return parse(stream, progressHandler); } finally { @@ -53,8 +54,8 @@ public abstract class FileParser { 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")); + final ProgressInputStream progressInputStream = new ProgressInputStream(is); + final BufferedReader input = new BufferedReader(new InputStreamReader(progressInputStream, CharEncoding.UTF_8)); try { String line; @@ -77,7 +78,7 @@ public abstract class FileParser { } } - protected static void fixCache(Geocache cache) { + protected static void fixCache(final Geocache cache) { if (cache.getInventory() != null) { cache.setInventoryItems(cache.getInventory().size()); } else { diff --git a/main/src/cgeo/geocaching/files/FileTypeDetector.java b/main/src/cgeo/geocaching/files/FileTypeDetector.java index ab0f032..d1a1892 100644 --- a/main/src/cgeo/geocaching/files/FileTypeDetector.java +++ b/main/src/cgeo/geocaching/files/FileTypeDetector.java @@ -3,6 +3,7 @@ package cgeo.geocaching.files; import cgeo.geocaching.utils.Log; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -19,7 +20,7 @@ public class FileTypeDetector { private final ContentResolver contentResolver; private final Uri uri; - public FileTypeDetector(Uri uri, ContentResolver contentResolver) { + public FileTypeDetector(final Uri uri, final ContentResolver contentResolver) { this.uri = uri; this.contentResolver = contentResolver; } @@ -33,10 +34,10 @@ public class FileTypeDetector { if (is == null) { return FileType.UNKNOWN; } - reader = new BufferedReader(new InputStreamReader(is)); + reader = new BufferedReader(new InputStreamReader(is, CharEncoding.UTF_8)); type = detectHeader(reader); reader.close(); - } catch (IOException e) { + } catch (final IOException e) { Log.e("FileTypeDetector", e); } finally { IOUtils.closeQuietly(reader); @@ -45,7 +46,7 @@ public class FileTypeDetector { return type; } - private static FileType detectHeader(BufferedReader reader) + private static FileType detectHeader(final BufferedReader reader) throws IOException { String line = reader.readLine(); if (isZip(line)) { @@ -65,7 +66,7 @@ public class FileTypeDetector { return FileType.UNKNOWN; } - private static boolean isZip(String line) { + private static boolean isZip(final String line) { return StringUtils.length(line) >= 4 && StringUtils.startsWith(line, "PK") && line.charAt(2) == 3 && line.charAt(3) == 4; diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java index 63a1844..2b1206c 100644 --- a/main/src/cgeo/geocaching/files/LocalStorage.java +++ b/main/src/cgeo/geocaching/files/LocalStorage.java @@ -7,7 +7,9 @@ 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.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -69,7 +71,7 @@ public final class LocalStorage { return getStorageSpecific(true); } - private static File getStorageSpecific(boolean secondary) { + private static File getStorageSpecific(final boolean secondary) { return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ^ secondary ? getExternalStorageBase() : new File(getInternalStorageBase(), LocalStorage.cache); @@ -202,7 +204,7 @@ public final class LocalStorage { saveHeader(HEADER_ETAG, saved ? response : null, targetFile); saveHeader(HEADER_LAST_MODIFIED, saved ? response : null, targetFile); return saved; - } catch (IOException e) { + } catch (final IOException e) { Log.e("LocalStorage.saveEntityToFile", e); } @@ -242,7 +244,7 @@ public final class LocalStorage { public static String getSavedHeader(final File baseFile, final String name) { try { final File file = filenameForHeader(baseFile, name); - final Reader f = new InputStreamReader(new FileInputStream(file), "UTF-8"); + final Reader f = new InputStreamReader(new FileInputStream(file), CharEncoding.UTF_8); try { // No header will be more than 256 bytes final char[] value = new char[256]; @@ -291,7 +293,7 @@ public final class LocalStorage { } finally { IOUtils.closeQuietly(inputStream); } - } catch (IOException e) { + } catch (final IOException e) { Log.e("LocalStorage.saveToFile", e); FileUtils.deleteIgnoringFailure(targetFile); } @@ -321,10 +323,10 @@ public final class LocalStorage { // close here already to catch any issue with closing input.close(); output.close(); - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { Log.e("LocalStorage.copy: could not copy file", e); return false; - } catch (IOException e) { + } catch (final IOException e) { Log.e("LocalStorage.copy: could not copy file", e); return false; } finally { @@ -345,7 +347,7 @@ public final class LocalStorage { } // Flushing is only necessary if the stream is not immediately closed afterwards. // We rely on all callers to do that correctly outside of this method - } catch (IOException e) { + } catch (final IOException e) { Log.e("LocalStorage.copy: error when copying data", e); return false; } @@ -398,7 +400,7 @@ public final class LocalStorage { if (!FileUtils.delete(file)) { Log.w("LocalStorage.deleteFilesPrefix: Can't delete file " + file.getName()); } - } catch (Exception e) { + } catch (final Exception e) { Log.e("LocalStorage.deleteFilesPrefix", e); } } @@ -417,7 +419,7 @@ public final class LocalStorage { public static File[] getFilesWithPrefix(final String geocode, final String filenamePrefix) { final FilenameFilter filter = new FilenameFilter() { @Override - public boolean accept(File dir, String filename) { + public boolean accept(final File dir, final String filename) { return filename.startsWith(filenamePrefix); } }; @@ -430,24 +432,24 @@ public final class LocalStorage { */ public static List<File> getStorages() { - String extStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); - List<File> storages = new ArrayList<>(); + final String extStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); + final List<File> storages = new ArrayList<>(); storages.add(new File(extStorage)); - File file = new File(FILE_SYSTEM_TABLE_PATH); + final File file = new File(FILE_SYSTEM_TABLE_PATH); if (file.canRead()) { Reader fr = null; BufferedReader br = null; try { - fr = new InputStreamReader(new FileInputStream(file), "UTF-8"); + fr = new InputStreamReader(new FileInputStream(file), CharEncoding.UTF_8); br = new BufferedReader(fr); String s = br.readLine(); while (s != null) { if (s.startsWith("dev_mount")) { - String[] tokens = StringUtils.split(s); + final String[] tokens = StringUtils.split(s); if (tokens.length >= 3) { - String path = tokens[2]; // mountpoint + final String path = tokens[2]; // mountpoint if (!extStorage.equals(path)) { - File directory = new File(path); + final File directory = new File(path); if (directory.exists() && directory.isDirectory()) { storages.add(directory); } @@ -456,7 +458,7 @@ public final class LocalStorage { } s = br.readLine(); } - } catch (IOException e) { + } catch (final IOException e) { Log.e("Could not get additional mount points for user content. " + "Proceeding with external storage only (" + extStorage + ")"); } finally { |
