]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/load/FileCacher.java
Version 15.2, November 2013
[GpsPrune.git] / tim / prune / load / FileCacher.java
index 63c8b24eacfd5a4d9354e35f48a99f6794d9a8a4..22383c6acb544f6f7e754f50e8b98eae1d645120 100644 (file)
@@ -12,7 +12,9 @@ import java.util.ArrayList;
  */
 public class FileCacher
 {
+       /** File to cache */
        private File _file = null;
+       /** Array to hold lines of file */
        private String[] _contentArray = null;
 
 
@@ -32,7 +34,7 @@ public class FileCacher
         */
        private void loadFile()
        {
-               ArrayList contentList = new ArrayList();
+               ArrayList<String> contentList = new ArrayList<String>();
                if (_file != null && _file.exists() && _file.canRead())
                {
                        BufferedReader reader = null;
@@ -40,8 +42,16 @@ public class FileCacher
                        {
                                reader = new BufferedReader(new FileReader(_file));
                                String currLine = reader.readLine();
+                               if (currLine != null && currLine.startsWith("<?xml")) {
+                                       return; // it's an xml file, it shouldn't use this cacher
+                               }
                                while (currLine != null)
                                {
+                                       if (currLine.indexOf('\0') >= 0)
+                                       {
+                                               try {reader.close();} catch (IOException ioe2) {}
+                                               return; // it's a binary file, shouldn't use this cacher
+                                       }
                                        if (currLine.trim().length() > 0)
                                                contentList.add(currLine);
                                        currLine = reader.readLine();
@@ -62,7 +72,7 @@ public class FileCacher
                int numLines = contentList.size();
                _contentArray = new String[numLines];
                for (int i=0; i<numLines; i++)
-                       _contentArray[i] = contentList.get(i).toString();
+                       _contentArray[i] = contentList.get(i);
        }