commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1486967 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/random/SobolSequenceGenerator.java
Date Tue, 28 May 2013 15:23:06 GMT
Author: tn
Date: Tue May 28 15:23:05 2013
New Revision: 1486967

URL: http://svn.apache.org/r1486967
Log:
Fix some findbugs warnings wrt input streams.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/random/SobolSequenceGenerator.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/random/SobolSequenceGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/random/SobolSequenceGenerator.java?rev=1486967&r1=1486966&r2=1486967&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/random/SobolSequenceGenerator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/random/SobolSequenceGenerator.java
Tue May 28 15:23:05 2013
@@ -20,6 +20,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
@@ -67,6 +68,9 @@ public class SobolSequenceGenerator impl
     /** The resource containing the direction numbers. */
     private static final String RESOURCE_NAME = "/assets/org/apache/commons/math3/random/new-joe-kuo-6.1000";
 
+    /** Character set for file input. */
+    private static final String FILE_CHARSET = "US-ASCII";
+
     /** Space dimension. */
     private final int dimension;
 
@@ -110,6 +114,12 @@ public class SobolSequenceGenerator impl
         } catch (MathParseException e) {
             // the internal resource file could not be parsed -> should not happen
             throw new MathInternalError();
+        } finally {
+            try {
+                is.close();
+            } catch (IOException e) { // NOPMD
+                // ignore
+            }
         }
     }
 
@@ -133,6 +143,8 @@ public class SobolSequenceGenerator impl
      * 2       1       0       1
      * 3       2       1       1 3
      * </pre>
+     * <p>
+     * The input stream <i>must</i> be an ASCII text containing one valid direction
vector per line.
      *
      * @param dimension the space dimension
      * @param is the stream to read the direction vectors from
@@ -164,6 +176,9 @@ public class SobolSequenceGenerator impl
 
     /**
      * Load the direction vector for each dimension from the given stream.
+     * <p>
+     * The input stream <i>must</i> be an ASCII text containing one
+     * valid direction vector per line.
      *
      * @param is the input stream to read the direction vector from
      * @return the last dimension that has been read from the input stream
@@ -177,7 +192,8 @@ public class SobolSequenceGenerator impl
             direction[0][i] = 1l << (BITS - i);
         }
 
-        final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+        final Charset charset = Charset.forName(FILE_CHARSET);
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(is, charset));
         int dim = -1;
 
         try {



Mime
View raw message