You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2014/09/14 01:34:59 UTC

svn commit: r1624791 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util: LuceneTestCase.java TestUtil.java

Author: uschindler
Date: Sat Sep 13 23:34:59 2014
New Revision: 1624791

URL: http://svn.apache.org/r1624791
Log:
LUCENE-5945: Cleanup & javadocs

Modified:
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1624791&r1=1624790&r2=1624791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java Sat Sep 13 23:34:59 2014
@@ -1663,9 +1663,9 @@ public abstract class LuceneTestCase ext
   }
 
   /**
-   * Gets a resource from the classpath as {@link Path}. This method should only
+   * Gets a resource from the test's classpath as {@link Path}. This method should only
    * be used, if a real file is needed. To get a stream, code should prefer
-   * {@link Class#getResourceAsStream} using {@code this.getClass()}.
+   * {@link #getDataInputStream(String)}.
    */
   protected Path getDataPath(String name) throws IOException {
     try {
@@ -1675,12 +1675,15 @@ public abstract class LuceneTestCase ext
     }
   }
 
+  /**
+   * Gets a resource from the test's classpath as {@link InputStream}.
+   */
   protected InputStream getDataInputStream(String name) throws IOException {
-    try {
-      return this.getClass().getResourceAsStream(name);
-    } catch (Exception e) {
+    InputStream in = this.getClass().getResourceAsStream(name);
+    if (in == null) {
       throw new IOException("Cannot find resource: " + name);
     }
+    return in;
   }
 
   public void assertReaderEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException {

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java?rev=1624791&r1=1624790&r2=1624791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java Sat Sep 13 23:34:59 2014
@@ -28,7 +28,6 @@ import java.nio.CharBuffer;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Arrays;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -108,6 +107,7 @@ public final class TestUtil {
 
     try (ZipInputStream zipInput = new ZipInputStream(in)) {
       ZipEntry entry;
+      byte[] buffer = new byte[8192];
       while ((entry = zipInput.getNextEntry()) != null) {
         Path targetFile = destDir.resolve(entry.getName());
         
@@ -116,7 +116,6 @@ public final class TestUtil {
         Files.createDirectories(targetFile.getParent());
         if (!entry.isDirectory()) {
           OutputStream out = Files.newOutputStream(targetFile);
-          byte[] buffer = new byte[8192];
           int len;
           while((len = zipInput.read(buffer)) >= 0) {
             out.write(buffer, 0, len);