You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by gs...@apache.org on 2011/05/21 12:47:19 UTC

svn commit: r1125664 - /mahout/trunk/utils/src/main/java/org/apache/mahout/text/PrefixAdditionFilter.java

Author: gsingers
Date: Sat May 21 10:47:19 2011
New Revision: 1125664

URL: http://svn.apache.org/viewvc?rev=1125664&view=rev
Log:
MAHOUT-694: close the stream

Modified:
    mahout/trunk/utils/src/main/java/org/apache/mahout/text/PrefixAdditionFilter.java

Modified: mahout/trunk/utils/src/main/java/org/apache/mahout/text/PrefixAdditionFilter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/utils/src/main/java/org/apache/mahout/text/PrefixAdditionFilter.java?rev=1125664&r1=1125663&r2=1125664&view=diff
==============================================================================
--- mahout/trunk/utils/src/main/java/org/apache/mahout/text/PrefixAdditionFilter.java (original)
+++ mahout/trunk/utils/src/main/java/org/apache/mahout/text/PrefixAdditionFilter.java Sat May 21 10:47:19 2011
@@ -20,6 +20,7 @@ package org.apache.mahout.text;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.IOUtils;
 import org.apache.mahout.common.iterator.FileLineIterable;
 
 import java.io.IOException;
@@ -43,16 +44,21 @@ public final class PrefixAdditionFilter 
                     new PrefixAdditionFilter(conf, prefix + Path.SEPARATOR + current.getName(),
                         options, writer));
     } else {
-      InputStream in = fs.open(fst.getPath());
+      InputStream in = null;
+      try {
+        in = fs.open(fst.getPath());
 
-      StringBuilder file = new StringBuilder();
-      for (String aFit : new FileLineIterable(in, charset, false)) {
-        file.append(aFit).append('\n');
+        StringBuilder file = new StringBuilder();
+        for (String aFit : new FileLineIterable(in, charset, false)) {
+          file.append(aFit).append('\n');
+        }
+        String name = current.getName().equals(fst.getPath().getName())
+            ? current.getName()
+            : current.getName() + Path.SEPARATOR + fst.getPath().getName();
+        writer.write(prefix + Path.SEPARATOR + name, file.toString());
+      } finally {
+        IOUtils.closeStream(in);
       }
-      String name = current.getName().equals(fst.getPath().getName())
-          ? current.getName()
-          : current.getName() + Path.SEPARATOR + fst.getPath().getName();
-      writer.write(prefix + Path.SEPARATOR + name, file.toString());
     }
   }
 }