]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/load/FileCacher.java
Version 7, February 2009
[GpsPrune.git] / tim / prune / load / FileCacher.java
index 733754bd83c0d98cdab258020907f89f98017430..de1e7caea8d6b2bd909943f6ad59f34661815096 100644 (file)
@@ -32,7 +32,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;
@@ -62,7 +62,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);
        }
 
 
@@ -77,7 +77,8 @@ public class FileCacher
 
        /**
         * Get the top section of the file for preview
-        * @param inSize number of lines to extract
+        * @param inNumRows number of lines to extract
+        * @param inMaxWidth max length of Strings (longer ones will be chopped)
         * @return String array containing non-blank lines from the file
         */
        public String[] getSnippet(int inNumRows, int inMaxWidth)
@@ -96,10 +97,15 @@ public class FileCacher
                {
                        for (int i=0; i<size; i++)
                        {
-                               if (result[i].length() > inMaxWidth)
-                                       result[i] = result[i].trim();
-                               if (result[i].length() > inMaxWidth)
-                                       result[i] = result[i].substring(0, inMaxWidth);
+                               if (result[i] == null)
+                                       result[i] = "";
+                               else
+                               {
+                                       if (result[i].length() > inMaxWidth)
+                                               result[i] = result[i].trim();
+                                       if (result[i].length() > inMaxWidth)
+                                               result[i] = result[i].substring(0, inMaxWidth);
+                               }
                        }
                }
                return result;