[jsword-svn] r2068 - in trunk/jsword: . src/main/java/org/crosswire/common/util src/main/java/org/crosswire/jsword/book/sword src/main/java/org/crosswire/jsword/passage

dmsmith at crosswire.org dmsmith at crosswire.org
Sat Jan 1 16:53:21 MST 2011


Author: dmsmith
Date: 2011-01-01 16:53:21 -0700 (Sat, 01 Jan 2011)
New Revision: 2068

Modified:
   trunk/jsword/JSwordDictionary.txt
   trunk/jsword/src/main/java/org/crosswire/common/util/NetUtil.java
   trunk/jsword/src/main/java/org/crosswire/common/util/StringUtil.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractPassage.java
Log:
JS-151 Provide an explicit buffer size to BufferedReaders.

Modified: trunk/jsword/JSwordDictionary.txt
===================================================================
--- trunk/jsword/JSwordDictionary.txt	2011-01-01 23:30:32 UTC (rev 2067)
+++ trunk/jsword/JSwordDictionary.txt	2011-01-01 23:53:21 UTC (rev 2068)
@@ -162,3 +162,4 @@
 placeholders
 dodgy
 malformed
+android

Modified: trunk/jsword/src/main/java/org/crosswire/common/util/NetUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/common/util/NetUtil.java	2011-01-01 23:30:32 UTC (rev 2067)
+++ trunk/jsword/src/main/java/org/crosswire/common/util/NetUtil.java	2011-01-01 23:53:21 UTC (rev 2068)
@@ -21,6 +21,7 @@
  */
 package org.crosswire.common.util;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -536,8 +537,13 @@
 
     /**
      * List all the files specified by the index file passed in. To be
-     * acceptable it must be a non-0 length string, not commented with #, not
-     * the index file itself and acceptable by the filter.
+     * acceptable it:
+     * <ul>
+     * <li> must be a non-0 length string,</li>
+     * <li> not commented with #,</li>
+     * <li> not the index file itself</li>
+     * <li> and acceptable by the filter.</li>
+     * </ul>
      * 
      * @return String[] Matching results.
      * @throws FileNotFoundException
@@ -546,19 +552,24 @@
         InputStream in = null;
         try {
             in = NetUtil.getInputStream(index);
-            String contents = StringUtil.read(new InputStreamReader(in));
+            // Quiet Android from complaining about using the default BufferReader buffer size.
+            // The actual buffer size is undocumented. So this is a good idea any way.
+            BufferedReader din = new BufferedReader(new InputStreamReader(in), 8192);
 
             // We still need to do the filtering
             List<String> list = new ArrayList<String>();
-            String[] names = StringUtil.split(contents, "\n");
-            for (int i = 0; i < names.length; i++) {
-                // we need to trim, as we may have \r\n not \n
-                String name = names[i].trim();
 
-                // to be acceptable it must be a non-0 length string, not
-                // commented
-                // with #, not the index file itself and acceptable by the
-                // filter.
+            while (true) {
+                String line = din.readLine();
+
+                if (line == null) {
+                    break;
+                }
+
+                // we need to trim extraneous whitespace on the line
+                String name = line.trim();
+
+                // Is it acceptable?
                 if (name.length() > 0 && name.charAt(0) != '#' && !name.equals(INDEX_FILE) && filter.accept(name)) {
                     list.add(name);
                 }
@@ -668,8 +679,7 @@
             URLConnection urlConnection = uri.toURL().openConnection();
             long time = urlConnection.getLastModified();
 
-            // If it were a jar then time contains the last modified date of the
-            // jar.
+            // If it were a jar then time contains the last modified date of the jar.
             if (urlConnection instanceof JarURLConnection) {
                 // form is jar:file:.../xxx.jar!.../filename.ext
                 JarURLConnection jarConnection = (JarURLConnection) urlConnection;

Modified: trunk/jsword/src/main/java/org/crosswire/common/util/StringUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/common/util/StringUtil.java	2011-01-01 23:30:32 UTC (rev 2067)
+++ trunk/jsword/src/main/java/org/crosswire/common/util/StringUtil.java	2011-01-01 23:53:21 UTC (rev 2068)
@@ -58,7 +58,9 @@
      */
     public static String read(Reader in) throws IOException {
         StringBuilder retcode = new StringBuilder();
-        BufferedReader din = new BufferedReader(in);
+        // Quiet Android from complaining about using the default BufferReader buffer size.
+        // The actual buffer size is undocumented. So this is a good idea any way.
+        BufferedReader din = new BufferedReader(in, 8192);
 
         while (true) {
             String line = din.readLine();

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java	2011-01-01 23:30:32 UTC (rev 2067)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java	2011-01-01 23:53:21 UTC (rev 2068)
@@ -92,8 +92,11 @@
         configFile = file;
 
         BufferedReader in = null;
+        int bufferSize = 8192;
         try {
-            in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_UTF8));
+            // Quiet Android from complaining about using the default BufferReader buffer size.
+            // The actual buffer size is undocumented. So this is a good idea any way.
+            in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_UTF8), bufferSize);
             loadInitials(in);
             loadContents(in);
             in.close();
@@ -105,7 +108,7 @@
                 readahead = null;
                 table.clear();
                 extra.clear();
-                in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_LATIN1));
+                in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_LATIN1), bufferSize);
                 loadInitials(in);
                 loadContents(in);
                 in.close();
@@ -134,7 +137,9 @@
     public void load(byte[] buffer) throws IOException {
         BufferedReader in = null;
         try {
-            in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_UTF8));
+            // Quiet Android from complaining about using the default BufferReader buffer size.
+            // The actual buffer size is undocumented. So this is a good idea any way.
+            in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_UTF8), buffer.length);
             loadInitials(in);
             loadContents(in);
             in.close();
@@ -146,7 +151,7 @@
                 readahead = null;
                 table.clear();
                 extra.clear();
-                in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_LATIN1));
+                in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_LATIN1), buffer.length);
                 loadInitials(in);
                 loadContents(in);
                 in.close();

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractPassage.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractPassage.java	2011-01-01 23:30:32 UTC (rev 2067)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractPassage.java	2011-01-01 23:53:21 UTC (rev 2068)
@@ -738,7 +738,9 @@
         raiseNormalizeProtection();
 
         int count = 0; // number of lines read
-        BufferedReader bin = new BufferedReader(in);
+        // Quiet Android from complaining about using the default BufferReader buffer size.
+        // The actual buffer size is undocumented. So this is a good idea any way.
+        BufferedReader bin = new BufferedReader(in, 8192);
         while (true) {
             String line = bin.readLine();
             if (line == null) {




More information about the jsword-svn mailing list