mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r1131350 [1/3] - in /mahout/trunk: core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/ core/src/main/java/org/apache/mahout/classifier/ core/src/main/java/org/apache...
Date Sat, 04 Jun 2011 08:43:01 GMT
Author: ssc
Date: Sat Jun  4 08:42:57 2011
New Revision: 1131350

URL: http://svn.apache.org/viewvc?rev=1131350&view=rev
Log:
MAHOUT-718 Small refactoring to broaden the use of Google Guava: Closeables

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/ClusterIterator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorCache.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/IOUtils.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/MahalanobisDistanceMeasure.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedDistanceMeasure.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/FileLineIterator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileIterator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileValueIterator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/DFUtils.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/DecisionForest.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Data.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Dataset.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/Classifier.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/partial/InterResults.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java
    mahout/trunk/core/src/main/java/org/apache/mahout/driver/MahoutDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/FPGrowthDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/ga/watchmaker/MahoutEvaluator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/HdfsBackedLanczosState.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/QJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDCli.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDSolver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/DictionaryVectorizer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/CollocMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TFPartialVectorReducer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFConverter.java
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/TasteTestCase.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesClassifierSelfTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesFileFormatterTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/ModelSerializerTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/ClusteringTestUtils.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/TestClusterClassifier.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/canopy/TestCanopyCreation.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/dirichlet/TestMapReduce.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/fuzzykmeans/TestFuzzyKmeansClustering.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/kmeans/TestKmeansClustering.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/minhash/TestMinHashClustering.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/spectral/common/TestVectorCache.java
    mahout/trunk/core/src/test/java/org/apache/mahout/df/data/Utils.java
    mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/InterResultsTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartialBuilderTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/FPGrowthTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthRetailDataTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/math/VectorWritableTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverDenseTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverSparseSequentialTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/DictionaryVectorizerTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/DocumentProcessorTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/SparseVectorsFromSequenceFilesTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/collocations/llr/GramKeyTest.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/DataFileIterator.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/ToCSV.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/Track1Runner.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Runner.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaXmlSplitter.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/XmlInputFormat.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/PrintResourceOrFile.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainNewsGroups.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/display/DisplayClustering.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/display/DisplaySpectralKMeans.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmDataConverter.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/TestForest.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/CDInfosTool.java
    mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/bayes/SplitBayesInputTest.java
    mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
    mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/CDInfosToolTest.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/benchmark/VectorBenchmarks.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/evaluation/RepresentativePointsDriver.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/text/ChunkedWriter.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromDirectory.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromMailArchives.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/RowIdJob.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/arff/Driver.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/DelimitedTermInfoWriter.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/SequenceFileVectorWriter.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/TextualVectorWriter.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/CachedTermInfo.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/Driver.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/TestClusterDumper.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/text/TestSequenceFilesFromDirectory.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/csv/CSVVectorIteratorTest.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/io/VectorWriterTest.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java Sat Jun  4 08:42:57 2011
@@ -22,6 +22,7 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
 
+import com.google.common.io.Closeables;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java Sat Jun  4 08:42:57 2011
@@ -28,6 +28,7 @@ import java.util.TreeMap;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.regex.Pattern;
 
+import com.google.common.io.Closeables;
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastByIDMap;
@@ -173,7 +174,7 @@ public class FileDataModel extends Abstr
       iterator.next();
       firstLine = iterator.peek();
     }
-    iterator.close();
+    Closeables.closeQuietly(iterator);
 
     delimiter = determineDelimiter(firstLine);
     delimiterPattern = Pattern.compile(String.valueOf(delimiter));

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java Sat Jun  4 08:42:57 2011
@@ -17,16 +17,13 @@
 
 package org.apache.mahout.classifier;
 
-import java.io.File;
-import java.io.FileFilter;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
+import java.io.*;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 
 import com.google.common.base.Charsets;
+import com.google.common.io.Closeables;
 import com.google.common.io.Files;
 import org.apache.commons.cli2.CommandLine;
 import org.apache.commons.cli2.Group;
@@ -78,7 +75,7 @@ public final class BayesFileFormatter {
       // listFiles() is called here as a way to recursively visit files,
       // actually
     } finally {
-      IOUtils.quietClose(writer);
+      Closeables.closeQuietly(writer);
     }
   }
   
@@ -105,7 +102,7 @@ public final class BayesFileFormatter {
       try {
         writeFile(label, analyzer, input, charset, writer);
       } finally {
-        IOUtils.quietClose(writer);
+        Closeables.closeQuietly(writer);
       }
     }
   }
@@ -173,7 +170,7 @@ public final class BayesFileFormatter {
           throw new IllegalStateException(e);
         } finally {
           if (writer == null) {
-            IOUtils.quietClose(theWriter);
+            Closeables.closeQuietly(theWriter);
           }
         }
       } else {
@@ -215,7 +212,7 @@ public final class BayesFileFormatter {
         writer.write(' ');
       }
     } finally {
-      IOUtils.quietClose(reader);
+      Closeables.closeQuietly(reader);
     }
   }
   

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java Sat Jun  4 08:42:57 2011
@@ -20,6 +20,7 @@ package org.apache.mahout.classifier.nai
 import java.io.IOException;
 import java.net.URI;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.FileSystem;
@@ -202,11 +203,14 @@ public final class NaiveBayesTrainer {
     
     SequenceFile.Writer dictWriter = new SequenceFile.Writer(fs, conf, labelMapPath, Text.class, IntWritable.class);
     int i = 0;
-    for (String label : labels) {
-      Writable key = new Text(label);
-      dictWriter.append(key, new IntWritable(i++));
+    try {
+      for (String label : labels) {
+        Writable key = new Text(label);
+        dictWriter.append(key, new IntWritable(i++));
+      }
+    } finally {
+      Closeables.closeQuietly(dictWriter);
     }
-    dictWriter.close();
     return labelMapPath;
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java Sat Jun  4 08:42:57 2011
@@ -40,7 +40,7 @@ public final class ModelSerializer {
     try {
       PolymorphicWritable.write(out, model);
     } finally {
-      Closeables.close(out, false);
+      Closeables.closeQuietly(out);
     }
   }
 
@@ -49,7 +49,7 @@ public final class ModelSerializer {
     try {
       PolymorphicWritable.write(out, model);
     } finally {
-      Closeables.close(out, false);
+      Closeables.closeQuietly(out);
     }
   }
 
@@ -58,7 +58,7 @@ public final class ModelSerializer {
     try {
       PolymorphicWritable.write(out, model);
     } finally {
-      Closeables.close(out, false);
+      Closeables.closeQuietly(out);
     }
   }
 
@@ -67,7 +67,7 @@ public final class ModelSerializer {
     try {
       return PolymorphicWritable.read(dataIn, clazz);
     } finally {
-      Closeables.close(in, false);
+      Closeables.closeQuietly(in);
     }
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/ClusterIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/ClusterIterator.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/ClusterIterator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/ClusterIterator.java Sat Jun  4 08:42:57 2011
@@ -130,7 +130,7 @@ public class ClusterIterator {
       Writable key = new Text(k);
       writer.append(key, classifier);
     } finally {
-      Closeables.close(writer, false);
+      Closeables.closeQuietly(writer);
     }
   }
   
@@ -143,7 +143,7 @@ public class ClusterIterator {
     try {
       reader.next(key, classifierOut);
     } finally {
-      Closeables.close(reader, false);
+      Closeables.closeQuietly(reader);
     }
     return classifierOut;
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java Sat Jun  4 08:42:57 2011
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -294,7 +295,7 @@ public class CanopyDriver extends Abstra
         writer.append(new Text(canopy.getIdentifier()), canopy);
       }
     } finally {
-      writer.close();
+      Closeables.closeQuietly(writer);
     }
     return canopyOutputDir;
   }
@@ -415,8 +416,8 @@ public class CanopyDriver extends Abstra
               .newInstance();
         }
       } finally {
-        reader.close();
-        writer.close();
+        Closeables.closeQuietly(reader);
+        Closeables.closeQuietly(writer);;
       }
     }
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java Sat Jun  4 08:42:57 2011
@@ -20,6 +20,7 @@ package org.apache.mahout.clustering.dir
 import java.io.IOException;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -278,8 +279,11 @@ public class DirichletDriver extends Abs
     for (int i = 0; i < numModels; i++) {
       Path path = new Path(stateOut, "part-" + i);
       SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, path, Text.class, DirichletCluster.class);
-      writer.append(new Text(Integer.toString(i)), state.getClusters().get(i));
-      writer.close();
+      try {
+        writer.append(new Text(Integer.toString(i)), state.getClusters().get(i));
+      } finally {
+        Closeables.closeQuietly(writer);
+      }
     }
   }
 
@@ -485,7 +489,7 @@ public class DirichletDriver extends Abs
           clusterer.emitPointToClusters(value, clusters, writer);
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
     }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java Sat Jun  4 08:42:57 2011
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -389,7 +390,7 @@ public class FuzzyKMeansDriver extends A
           writer.append(new Text(cluster.getIdentifier()), cluster);
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
       clustersIn = clustersOut;
       iteration++;
@@ -486,7 +487,7 @@ public class FuzzyKMeansDriver extends A
           clusterer.emitPointToClusters(value, clusters, writer);
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
     }
 
@@ -554,12 +555,14 @@ public class FuzzyKMeansDriver extends A
     boolean converged = true;
 
     for (Path path : result) {
-      SequenceFileValueIterator<SoftCluster> iterator =
-          new SequenceFileValueIterator<SoftCluster>(path, true, conf);
-      while (converged && iterator.hasNext()) {
-        converged = iterator.next().isConverged();
+      SequenceFileValueIterator<SoftCluster> iterator = new SequenceFileValueIterator<SoftCluster>(path, true, conf);
+      try {
+        while (converged && iterator.hasNext()) {
+          converged = iterator.next().isConverged();
+        }
+      } finally {
+        Closeables.closeQuietly(iterator);
       }
-      iterator.close();
     }
 
     return converged;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java Sat Jun  4 08:42:57 2011
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -285,7 +286,7 @@ public class KMeansDriver extends Abstra
           writer.append(new Text(cluster.getIdentifier()), cluster);
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
       clustersIn = clustersOut;
       iteration++;
@@ -382,7 +383,7 @@ public class KMeansDriver extends Abstra
       while (iterator.hasNext()) {
         Cluster value = iterator.next();
         if (!value.isConverged()) {
-          iterator.close();
+          Closeables.closeQuietly(iterator);
           return false;
         }
       }
@@ -451,7 +452,7 @@ public class KMeansDriver extends Abstra
           clusterer.emitPointToNearestCluster(value.get(), clusters, writer);
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
     }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java Sat Jun  4 08:42:57 2011
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -103,12 +104,15 @@ public final class RandomSeedGenerator {
           }
         }
       }
-      
-      for (int i = 0; i < k; i++) {
-        writer.append(chosenTexts.get(i), chosenClusters.get(i));
+
+      try {
+        for (int i = 0; i < k; i++) {
+          writer.append(chosenTexts.get(i), chosenClusters.get(i));
+        }
+        log.info("Wrote {} vectors to {}", k, outFile);
+      } finally {
+        Closeables.closeQuietly(writer);
       }
-      log.info("Wrote {} vectors to {}", k, outFile);
-      writer.close();
     }
     
     return outFile;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java Sat Jun  4 08:42:57 2011
@@ -18,6 +18,7 @@
 package org.apache.mahout.clustering.lda;
 
 import com.google.common.base.Preconditions;
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -263,20 +264,22 @@ public final class LDADriver extends Abs
       Path path = new Path(statePath, "part-" + k);
       SequenceFile.Writer writer = new SequenceFile.Writer(fs, job, path, IntPairWritable.class, DoubleWritable.class);
 
-      double total = 0.0; // total number of pseudo counts we made
-      for (int w = 0; w < numWords; ++w) {
-        Writable kw = new IntPairWritable(k, w);
-        // A small amount of random noise, minimized by having a floor.
-        double pseudocount = random.nextDouble() + 1.0E-8;
-        total += pseudocount;
-        v.set(Math.log(pseudocount));
-        writer.append(kw, v);
+      try {
+        double total = 0.0; // total number of pseudo counts we made
+        for (int w = 0; w < numWords; ++w) {
+          Writable kw = new IntPairWritable(k, w);
+          // A small amount of random noise, minimized by having a floor.
+          double pseudocount = random.nextDouble() + 1.0E-8;
+          total += pseudocount;
+          v.set(Math.log(pseudocount));
+          writer.append(kw, v);
+        }
+        Writable kTsk = new IntPairWritable(k, TOPIC_SUM_KEY);
+        v.set(Math.log(total));
+        writer.append(kTsk, v);
+      } finally {
+        Closeables.closeQuietly(writer);
       }
-      Writable kTsk = new IntPairWritable(k, TOPIC_SUM_KEY);
-      v.set(Math.log(total));
-      writer.append(kTsk, v);
-
-      writer.close();
     }
   }
 
@@ -288,22 +291,28 @@ public final class LDADriver extends Abs
       Path path = new Path(statePath, "part-" + k);
       SequenceFile.Writer writer = new SequenceFile.Writer(fs, job, path, IntPairWritable.class, DoubleWritable.class);
 
-      for (int w = 0; w < state.getNumWords(); ++w) {
-        Writable kw = new IntPairWritable(k, w);
-        v.set(state.logProbWordGivenTopic(w,k) + state.getLogTotal(k));
-        writer.append(kw, v);
+      try {
+        for (int w = 0; w < state.getNumWords(); ++w) {
+          Writable kw = new IntPairWritable(k, w);
+          v.set(state.logProbWordGivenTopic(w,k) + state.getLogTotal(k));
+          writer.append(kw, v);
+        }
+        Writable kTsk = new IntPairWritable(k, TOPIC_SUM_KEY);
+        v.set(state.getLogTotal(k));
+        writer.append(kTsk, v);
+      } finally {
+        Closeables.closeQuietly(writer);
       }
-      Writable kTsk = new IntPairWritable(k, TOPIC_SUM_KEY);
-      v.set(state.getLogTotal(k));
-      writer.append(kTsk, v);
-      writer.close();
     }
     Path path = new Path(statePath, "part-" + LOG_LIKELIHOOD_KEY);
     SequenceFile.Writer writer = new SequenceFile.Writer(fs, job, path, IntPairWritable.class, DoubleWritable.class);
-    Writable kTsk = new IntPairWritable(LOG_LIKELIHOOD_KEY,LOG_LIKELIHOOD_KEY);
-    v.set(state.getLogLikelihood());
-    writer.append(kTsk, v);
-    writer.close();
+    try {
+      Writable kTsk = new IntPairWritable(LOG_LIKELIHOOD_KEY,LOG_LIKELIHOOD_KEY);
+      v.set(state.getLogLikelihood());
+      writer.append(kTsk, v);
+    } finally {
+      Closeables.closeQuietly(writer);
+    }
   }
 
   private static double findLL(Path statePath, Configuration job) throws IOException {
@@ -313,14 +322,17 @@ public final class LDADriver extends Abs
       Path path = status.getPath();
       SequenceFileIterator<IntPairWritable,DoubleWritable> iterator =
           new SequenceFileIterator<IntPairWritable,DoubleWritable>(path, true, job);
-      while (iterator.hasNext()) {
-        Pair<IntPairWritable,DoubleWritable> record = iterator.next();
-        if (record.getFirst().getFirst() == LOG_LIKELIHOOD_KEY) {
-          ll = record.getSecond().get();
-          break;
+      try {
+        while (iterator.hasNext()) {
+          Pair<IntPairWritable,DoubleWritable> record = iterator.next();
+          if (record.getFirst().getFirst() == LOG_LIKELIHOOD_KEY) {
+            ll = record.getSecond().get();
+            break;
+          }
         }
+      } finally {
+        Closeables.closeQuietly(iterator);
       }
-      iterator.close();
     }
     return ll;
   }
@@ -455,23 +467,25 @@ public final class LDADriver extends Abs
     Class<? extends Writable> keyClass = peekAtSequenceFileForKeyType(conf, input);
     SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, outputPath, keyClass, VectorWritable.class);
 
-    Writable key = ReflectionUtils.newInstance(keyClass, conf);
-    Writable vw = new VectorWritable();
+    try {
+      Writable key = ReflectionUtils.newInstance(keyClass, conf);
+      Writable vw = new VectorWritable();
 
-    for(Pair<Writable, VectorWritable> slice : trainingCorpus) {
-      Vector wordCounts = slice.getSecond().get();
-      try {
-        inference.infer(wordCounts);
-      } catch (ArrayIndexOutOfBoundsException e1) {
-        throw new IllegalStateException(
-         "This is probably because the --numWords argument is set too small.  \n"
-         + "\tIt needs to be >= than the number of words (terms actually) in the corpus and can be \n"
-         + "\tlarger if some storage inefficiency can be tolerated.", e1);
+      for(Pair<Writable, VectorWritable> slice : trainingCorpus) {
+        Vector wordCounts = slice.getSecond().get();
+        try {
+          inference.infer(wordCounts);
+        } catch (ArrayIndexOutOfBoundsException e1) {
+          throw new IllegalStateException(
+           "This is probably because the --numWords argument is set too small.  \n"
+           + "\tIt needs to be >= than the number of words (terms actually) in the corpus and can be \n"
+           + "\tlarger if some storage inefficiency can be tolerated.", e1);
+        }
+        writer.append(key, vw);
       }
-      writer.append(key, vw);
+    } finally {
+      Closeables.closeQuietly(writer);
     }
-
-    writer.close();
   }
 
   private static Class<? extends Writable> peekAtSequenceFileForKeyType(Configuration conf, Path input) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java Sat Jun  4 08:42:57 2011
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -212,7 +213,7 @@ public class MeanShiftCanopyDriver exten
           writer.append(new Text(), MeanShiftCanopy.initialCanopy(value.get(), id++, measure));
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
     }
   }
@@ -322,7 +323,7 @@ public class MeanShiftCanopyDriver exten
           writer.append(new Text(cluster.getIdentifier()), cluster);
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
       clustersIn = clustersOut;
       iteration++;
@@ -463,7 +464,7 @@ public class MeanShiftCanopyDriver exten
           writer.append(new IntWritable(closest.getId()), new WeightedVectorWritable(1, canopy.getCenter()));
         }
       } finally {
-        writer.close();
+        Closeables.closeQuietly(writer);
       }
     }
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorCache.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorCache.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorCache.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorCache.java Sat Jun  4 08:42:57 2011
@@ -20,6 +20,7 @@ package org.apache.mahout.clustering.spe
 import java.io.IOException;
 import java.net.URI;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.FileSystem;
@@ -66,9 +67,12 @@ public final class VectorCache {
     // set up the writer
     SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, output, 
         IntWritable.class, VectorWritable.class);
-    writer.append(key, new VectorWritable(vector));
-    writer.close();
-    
+    try {
+      writer.append(key, new VectorWritable(vector));
+    } finally {
+      Closeables.closeQuietly(writer);
+    }
+
     if (deleteOnExit) {
       fs.deleteOnExit(output);
     }
@@ -99,8 +103,10 @@ public final class VectorCache {
   public static Vector load(Configuration conf, Path input) throws IOException {
     SequenceFileValueIterator<VectorWritable> iterator =
         new SequenceFileValueIterator<VectorWritable>(input, true, conf);
-    VectorWritable vectorWritable = iterator.next();
-    iterator.close();
-    return vectorWritable.get();
+    try {
+      return iterator.next().get();
+    } finally {
+      Closeables.closeQuietly(iterator);
+    }
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/IOUtils.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/IOUtils.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/IOUtils.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/IOUtils.java Sat Jun  4 08:42:57 2011
@@ -43,7 +43,6 @@ public final class IOUtils {
   private IOUtils() { }
   
   public static void quietClose(Closeable... closeables) {
-    Preconditions.checkNotNull(closeables, "Closables cannot be null");
     for (Closeable closeable : closeables) {
       Closeables.closeQuietly(closeable);
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/MahalanobisDistanceMeasure.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/MahalanobisDistanceMeasure.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/MahalanobisDistanceMeasure.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/MahalanobisDistanceMeasure.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -79,7 +80,7 @@ public class MahalanobisDistanceMeasure 
         try {
           inverseCovarianceMatrix.readFields(in);
         } finally {
-          in.close();
+          Closeables.closeQuietly(in);
         }
         this.inverseCovarianceMatrix = inverseCovarianceMatrix.get();
       }
@@ -94,7 +95,7 @@ public class MahalanobisDistanceMeasure 
         try {
           meanVector.readFields(in);
         } finally {
-          in.close();
+          Closeables.closeQuietly(in);
         }
         this.meanVector = meanVector.get();
       }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedDistanceMeasure.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedDistanceMeasure.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedDistanceMeasure.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedDistanceMeasure.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -74,7 +75,7 @@ public abstract class WeightedDistanceMe
         try {
           weights.readFields(in);
         } finally {
-          in.close();
+          Closeables.closeQuietly(in);
         }
         this.weights = weights.get();
       }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/FileLineIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/FileLineIterator.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/FileLineIterator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/FileLineIterator.java Sat Jun  4 08:42:57 2011
@@ -30,6 +30,7 @@ import java.util.zip.ZipInputStream;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.AbstractIterator;
+import com.google.common.io.Closeables;
 import org.apache.mahout.cf.taste.impl.common.SkippingIterator;
 import org.apache.mahout.common.IOUtils;
 
@@ -135,7 +136,7 @@ public final class FileLineIterator exte
   @Override
   public void close() {
     endOfData();
-    IOUtils.quietClose(reader);
+    Closeables.closeQuietly(reader);
   }
   
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileIterator.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileIterator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileIterator.java Sat Jun  4 08:42:57 2011
@@ -21,6 +21,7 @@ import java.io.Closeable;
 import java.io.IOException;
 
 import com.google.common.collect.AbstractIterator;
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -75,7 +76,7 @@ public final class SequenceFileIterator<
   public void close() {
     key = null;
     value = null;
-    IOUtils.quietClose(reader);
+    Closeables.closeQuietly(reader);
     endOfData();
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileValueIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileValueIterator.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileValueIterator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/sequencefile/SequenceFileValueIterator.java Sat Jun  4 08:42:57 2011
@@ -21,6 +21,7 @@ import java.io.Closeable;
 import java.io.IOException;
 
 import com.google.common.collect.AbstractIterator;
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -63,7 +64,7 @@ public final class SequenceFileValueIter
   @Override
   public void close() {
     value = null;
-    IOUtils.quietClose(reader);
+    Closeables.closeQuietly(reader);
     endOfData();
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/DFUtils.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/DFUtils.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/DFUtils.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/DFUtils.java Sat Jun  4 08:42:57 2011
@@ -21,6 +21,7 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FSDataOutputStream;
@@ -138,7 +139,10 @@ public final class DFUtils {
     FileSystem fs = path.getFileSystem(conf);
 
     FSDataOutputStream out = fs.create(path);
-    writable.write(out);
-    out.close();
+    try {
+      writable.write(out);
+    } finally {
+      Closeables.closeQuietly(out);
+    }
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/DecisionForest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/DecisionForest.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/DecisionForest.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/DecisionForest.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.io.DataOutput;
 import java.io.IOException;
 import java.io.DataInput;
 
+import com.google.common.io.Closeables;
 import org.apache.mahout.df.callback.PredictionCallback;
 import org.apache.mahout.df.data.Data;
 import org.apache.mahout.df.data.DataUtils;
@@ -208,7 +209,7 @@ public class DecisionForest implements W
           forest.readFields(dataInput);
         }
       } finally {
-        dataInput.close();
+        Closeables.closeQuietly(dataInput);
       }
     }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Data.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Data.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Data.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Data.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Random;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -295,13 +296,15 @@ public class Data implements Cloneable {
     DataConverter converter = new DataConverter(dataset);
     
     int index = 0;
-    
-    while (iterator.hasNext()) {
-      labels[index++] = converter.convert(0, iterator.next()).getLabel();
+
+    try {
+      while (iterator.hasNext()) {
+        labels[index++] = converter.convert(0, iterator.next()).getLabel();
+      }
+    } finally {
+      Closeables.closeQuietly(iterator);
     }
     
-    iterator.close();
-    
     return labels;
   }
   

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Dataset.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Dataset.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Dataset.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/data/Dataset.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import com.google.common.base.Preconditions;
+import com.google.common.io.Closeables;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
@@ -280,13 +281,12 @@ public class Dataset implements Writable
    */
   public static Dataset load(Configuration conf, Path path) throws IOException {
     FileSystem fs = path.getFileSystem(conf);
-    
     FSDataInputStream input = fs.open(path);
-    
-    Dataset dataset = read(input);
-    input.close();
-    
-    return dataset;
+    try {
+      return read(input);
+    } finally {
+      Closeables.closeQuietly(input);
+    }
   }
   
   public static Dataset read(DataInput in) throws IOException {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/Classifier.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/Classifier.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/Classifier.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/Classifier.java Sat Jun  4 08:42:57 2011
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.df.mapreduce;
 
+import com.google.common.io.Closeables;
 import org.apache.mahout.common.HadoopUtil;
 import org.apache.mahout.common.Pair;
 import org.apache.mahout.common.iterator.sequencefile.SequenceFileIterable;
@@ -178,7 +179,7 @@ public class Classifier {
           }
         }
       } finally {
-        ofile.close();
+        Closeables.closeQuietly(ofile);
       }
     }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/partial/InterResults.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/partial/InterResults.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/partial/InterResults.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/partial/InterResults.java Sat Jun  4 08:42:57 2011
@@ -18,6 +18,7 @@ package org.apache.mahout.df.mapreduce.p
 
 import java.io.IOException;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
@@ -96,7 +97,7 @@ public final class InterResults {
         throw new IllegalStateException("loaded less keys/trees than expected");
       }
     } finally {
-      in.close();
+      Closeables.closeQuietly(in);
     }
 
     return numInstances;
@@ -126,19 +127,21 @@ public final class InterResults {
     int numMaps = sizes.length;
     
     FSDataOutputStream out = fs.create(forestPath);
-    
-    // write partitions' sizes
-    for (int p = 0; p < numMaps; p++) {
-      out.writeInt(sizes[p]);
-    }
-    
-    // write the data
-    for (int index = 0; index < numTrees; index++) {
-      keys[index].write(out);
-      trees[index].write(out);
+
+    try {
+      // write partitions' sizes
+      for (int p = 0; p < numMaps; p++) {
+        out.writeInt(sizes[p]);
+      }
+
+      // write the data
+      for (int index = 0; index < numTrees; index++) {
+        keys[index].write(out);
+        trees[index].write(out);
+      }
+    } finally {
+      Closeables.closeQuietly(out);
     }
-    
-    out.close();
   }
   
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java Sat Jun  4 08:42:57 2011
@@ -23,6 +23,7 @@ import java.util.Locale;
 import java.util.Random;
 import java.util.Scanner;
 
+import com.google.common.io.Closeables;
 import org.apache.commons.cli2.CommandLine;
 import org.apache.commons.cli2.Group;
 import org.apache.commons.cli2.Option;
@@ -188,7 +189,7 @@ public final class UDistrib {
     // close all the files.
     scanner.close();
     for (FSDataOutputStream file : files) {
-      file.close();
+      Closeables.closeQuietly(file);
     }
     
     // merge all output files

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/driver/MahoutDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/driver/MahoutDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/driver/MahoutDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/driver/MahoutDriver.java Sat Jun  4 08:42:57 2011
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.util.ProgramDriver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -202,7 +203,7 @@ public final class MahoutDriver {
         log.warn("Error while loading {}", resource, ioe);
         // Continue
       } finally {
-        propsStream.close();
+        Closeables.closeQuietly(propsStream);
       }
     }
     return null;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/FPGrowthDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/FPGrowthDriver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/FPGrowthDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/FPGrowthDriver.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.commons.cli2.CommandLine;
 import org.apache.commons.cli2.Group;
 import org.apache.commons.cli2.Option;
@@ -191,18 +192,21 @@ public final class FPGrowthDriver {
     
     FPGrowth<String> fp = new FPGrowth<String>();
     Collection<String> features = new HashSet<String>();
-    
-    fp.generateTopKFrequentPatterns(
-        new StringRecordIterator(new FileLineIterable(new File(input), encoding, false), pattern),
-        fp.generateFList(
-            new StringRecordIterator(new FileLineIterable(new File(input), encoding, false), pattern),
-            minSupport),
-        minSupport,
-        maxHeapSize,
-        features,
-        new StringOutputConverter(new SequenceFileOutputCollector<Text,TopKStringPatterns>(writer)),
-        new ContextStatusUpdater(null));
-    writer.close();
+
+    try {
+      fp.generateTopKFrequentPatterns(
+          new StringRecordIterator(new FileLineIterable(new File(input), encoding, false), pattern),
+          fp.generateFList(
+              new StringRecordIterator(new FileLineIterable(new File(input), encoding, false), pattern),
+              minSupport),
+          minSupport,
+          maxHeapSize,
+          features,
+          new StringOutputConverter(new SequenceFileOutputCollector<Text,TopKStringPatterns>(writer)),
+          new ContextStatusUpdater(null));
+    } finally {
+      Closeables.closeQuietly(writer);
+    }
     
     List<Pair<String,TopKStringPatterns>> frequentPatterns = FPGrowth.readFrequentPattern(conf, path);
     for (Pair<String,TopKStringPatterns> entry : frequentPatterns) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/ga/watchmaker/MahoutEvaluator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/ga/watchmaker/MahoutEvaluator.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/ga/watchmaker/MahoutEvaluator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/ga/watchmaker/MahoutEvaluator.java Sat Jun  4 08:42:57 2011
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.util.Collection;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
@@ -130,7 +131,7 @@ public final class MahoutEvaluator {
         writer.newLine();
       }
     } finally {
-      writer.close();
+      Closeables.closeQuietly(writer);
     }
   }
   

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java Sat Jun  4 08:42:57 2011
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.math.hadoop;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.FileSystem;
@@ -160,7 +161,7 @@ public final class TimesSquaredJob {
             conf, inputVectorPath, NullWritable.class, VectorWritable.class);
     Writable inputVW = new VectorWritable(v);
     inputVectorPathWriter.append(NullWritable.get(), inputVW);
-    inputVectorPathWriter.close();
+    Closeables.close(inputVectorPathWriter, false);
     URI ivpURI = inputVectorPath.toUri();
     DistributedCache.setCacheFiles(new URI[] {ivpURI}, conf);
 
@@ -186,9 +187,11 @@ public final class TimesSquaredJob {
     Path outputFile = new Path(outputPath, "part-00000");
     SequenceFileValueIterator<VectorWritable> iterator =
         new SequenceFileValueIterator<VectorWritable>(outputFile, true, conf);
-    Vector vector = iterator.next().get();
-    iterator.close();
-    return vector;
+    try {
+      return iterator.next().get();
+    } finally {
+      Closeables.closeQuietly(iterator);
+    }
   }
 
   public static class TimesSquaredMapper<T extends WritableComparable> extends MapReduceBase
@@ -208,8 +211,11 @@ public final class TimesSquaredJob {
 
         SequenceFileValueIterator<VectorWritable> iterator =
             new SequenceFileValueIterator<VectorWritable>(inputVectorPath, true, conf);
-        inputVector = iterator.next().get();
-        iterator.close();
+        try {
+          inputVector = iterator.next().get();
+        } finally {
+          Closeables.closeQuietly(iterator);
+        }
 
         int outDim = conf.getInt(OUTPUT_VECTOR_DIMENSION, Integer.MAX_VALUE);
         outputVector = conf.getBoolean(IS_SPARSE_OUTPUT, false)

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java Sat Jun  4 08:42:57 2011
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.math.hadoop.decomposer;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -225,16 +226,19 @@ public class DistributedLanczosSolver ex
     FileSystem fs = FileSystem.get(conf);
     SequenceFile.Writer seqWriter =
         new SequenceFile.Writer(fs, conf, outputPath, IntWritable.class, VectorWritable.class);
-    IntWritable iw = new IntWritable();
-    for (int i = 0; i < numEigenVectors; i++) {
-      // Persist eigenvectors sorted by eigenvalues in descending order\
-      NamedVector v = new NamedVector(state.getRightSingularVector(numEigenVectors - 1 - i),
-          "eigenVector" + i + ", eigenvalue = " + state.getSingularValue(numEigenVectors - 1 - i));
-      Writable vw = new VectorWritable(v);
-      iw.set(i);
-      seqWriter.append(iw, vw);
+    try {
+      IntWritable iw = new IntWritable();
+      for (int i = 0; i < numEigenVectors; i++) {
+        // Persist eigenvectors sorted by eigenvalues in descending order\
+        NamedVector v = new NamedVector(state.getRightSingularVector(numEigenVectors - 1 - i),
+            "eigenVector" + i + ", eigenvalue = " + state.getSingularValue(numEigenVectors - 1 - i));
+        Writable vw = new VectorWritable(v);
+        iw.set(i);
+        seqWriter.append(iw, vw);
+      }
+    } finally {
+      Closeables.closeQuietly(seqWriter);
     }
-    seqWriter.close();
   }
 
   @Override

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java Sat Jun  4 08:42:57 2011
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.math.hadoop.decomposer;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -189,30 +190,33 @@ public class EigenVerificationJob extend
     Path path = new Path(outPath, CLEAN_EIGENVECTORS);
     FileSystem fs = FileSystem.get(conf);
     SequenceFile.Writer seqWriter = new SequenceFile.Writer(fs, conf, path, IntWritable.class, VectorWritable.class);
-    IntWritable iw = new IntWritable();
-    int numEigensWritten = 0;
-    for (Map.Entry<MatrixSlice, EigenStatus> pruneSlice : prunedEigenMeta) {
-      MatrixSlice s = pruneSlice.getKey();
-      EigenStatus meta = pruneSlice.getValue();
-      EigenVector ev = new EigenVector(s.vector(),
-                                       meta.getEigenValue(),
-                                       Math.abs(1 - meta.getCosAngle()),
-                                       s.index());
-      log.info("appending {} to {}", ev, path);
-      Writable vw = new VectorWritable(ev);
-      iw.set(s.index());
-      seqWriter.append(iw, vw);
-
-      // increment the number of eigenvectors written and see if we've
-      // reached our specified limit, or if we wish to write all eigenvectors
-      // (latter is built-in, since numEigensWritten will always be > 0
-      numEigensWritten++;
-      if (numEigensWritten == maxEigensToKeep) {
-        log.info("{} of the {} total eigens have been written", maxEigensToKeep, prunedEigenMeta.size());
-        break;
+    try {
+      IntWritable iw = new IntWritable();
+      int numEigensWritten = 0;
+      for (Map.Entry<MatrixSlice, EigenStatus> pruneSlice : prunedEigenMeta) {
+        MatrixSlice s = pruneSlice.getKey();
+        EigenStatus meta = pruneSlice.getValue();
+        EigenVector ev = new EigenVector(s.vector(),
+                                         meta.getEigenValue(),
+                                         Math.abs(1 - meta.getCosAngle()),
+                                         s.index());
+        log.info("appending {} to {}", ev, path);
+        Writable vw = new VectorWritable(ev);
+        iw.set(s.index());
+        seqWriter.append(iw, vw);
+
+        // increment the number of eigenvectors written and see if we've
+        // reached our specified limit, or if we wish to write all eigenvectors
+        // (latter is built-in, since numEigensWritten will always be > 0
+        numEigensWritten++;
+        if (numEigensWritten == maxEigensToKeep) {
+          log.info("{} of the {} total eigens have been written", maxEigensToKeep, prunedEigenMeta.size());
+          break;
+        }
       }
+    } finally {
+      Closeables.closeQuietly(seqWriter);
     }
-    seqWriter.close();
     cleanedEigensPath = path;
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/HdfsBackedLanczosState.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/HdfsBackedLanczosState.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/HdfsBackedLanczosState.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/HdfsBackedLanczosState.java Sat Jun  4 08:42:57 2011
@@ -1,5 +1,6 @@
 package org.apache.mahout.math.hadoop.decomposer;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configurable;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
@@ -131,9 +132,7 @@ public class HdfsBackedLanczosState exte
           IntWritable.class, VectorWritable.class);
       writer.append(new IntWritable(key), new VectorWritable(vector));
     } finally {
-      if(writer != null) {
-        writer.close();
-      }
+      Closeables.closeQuietly(writer);
     }
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java Sat Jun  4 08:42:57 2011
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -122,9 +123,7 @@ public final class BtJob {
 
     @Override
     protected void cleanup(Context context) throws IOException, InterruptedException {
-      if (qInput != null) {
-        qInput.close();
-      }
+      Closeables.closeQuietly(qInput);
       if (outputs != null) {
         outputs.close();
       }
@@ -217,7 +216,7 @@ public final class BtJob {
         try {
           rValue = iterator.next();
         } finally {
-          iterator.close();
+          Closeables.closeQuietly(iterator);
         }
         if (block < blockNum && block > 0) {
           GivensThinSolver.mergeR(mRs.get(0), new UpperTriangular(rValue.get()));

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/QJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/QJob.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/QJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/QJob.java Sat Jun  4 08:42:57 2011
@@ -27,6 +27,7 @@ import java.util.Deque;
 import java.util.LinkedList;
 import java.util.List;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -262,7 +263,7 @@ public final class QJob {
           flushSolver(context);
           assert tempQw != null;
           closeables.remove(tempQw);
-          tempQw.close();
+          Closeables.closeQuietly(tempQw);
         }
         flushQBlocks(context);
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDCli.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDCli.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDCli.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDCli.java Sat Jun  4 08:42:57 2011
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.Arrays;
 import java.util.Map;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -104,7 +105,7 @@ public class SSVDCli extends AbstractJob
       sigmaW.append(NullWritable.get(), sValues);
 
     } finally {
-      sigmaW.close();
+      Closeables.closeQuietly(sigmaW);
     }
 
     if (computeU) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDSolver.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDSolver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDSolver.java Sat Jun  4 08:42:57 2011
@@ -29,6 +29,7 @@ import java.util.Random;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -311,7 +312,7 @@ public class SSVDSolver {
       }
 
       closeables.remove(uHatWriter);
-      uHatWriter.close();
+      Closeables.closeQuietly(uHatWriter);
 
       SequenceFile.Writer svWriter = SequenceFile.createWriter(fs, conf,
           svPath = new Path(svPath, "svalues.seq"), IntWritable.class,
@@ -323,7 +324,7 @@ public class SSVDSolver {
       svWriter.append(iw, vw);
 
       closeables.remove(svWriter);
-      svWriter.close();
+      Closeables.closeQuietly(svWriter);
 
       UJob ujob = null;
       if (computeU) {
@@ -374,7 +375,7 @@ public class SSVDSolver {
       try {
         return r.getKeyClass().asSubclass(Writable.class);
       } finally {
-        r.close();
+        Closeables.closeQuietly(r);
       }
     }
     throw new IOException("Unable to open input files to determine input label type.");

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/DictionaryVectorizer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/DictionaryVectorizer.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/DictionaryVectorizer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/DictionaryVectorizer.java Sat Jun  4 08:42:57 2011
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.List;
 
 import com.google.common.base.Preconditions;
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.FileSystem;
@@ -206,30 +207,33 @@ public final class DictionaryVectorizer 
     chunkPaths.add(chunkPath);
     
     SequenceFile.Writer dictWriter = new SequenceFile.Writer(fs, conf, chunkPath, Text.class, IntWritable.class);
-    
-    long currentChunkSize = 0;
-    Path filesPattern = new Path(wordCountPath, OUTPUT_FILES_PATTERN);
-    int i = 0;
-    for (Pair<Writable,Writable> record
-         : new SequenceFileDirIterable<Writable,Writable>(filesPattern, PathType.GLOB, null, null, true, conf)) {
-      if (currentChunkSize > chunkSizeLimit) {
-        dictWriter.close();
-        chunkIndex++;
 
-        chunkPath = new Path(dictionaryPathBase, DICTIONARY_FILE + chunkIndex);
-        chunkPaths.add(chunkPath);
+    try {
+      long currentChunkSize = 0;
+      Path filesPattern = new Path(wordCountPath, OUTPUT_FILES_PATTERN);
+      int i = 0;
+      for (Pair<Writable,Writable> record
+           : new SequenceFileDirIterable<Writable,Writable>(filesPattern, PathType.GLOB, null, null, true, conf)) {
+        if (currentChunkSize > chunkSizeLimit) {
+          Closeables.closeQuietly(dictWriter);
+          chunkIndex++;
 
-        dictWriter = new SequenceFile.Writer(fs, conf, chunkPath, Text.class, IntWritable.class);
-        currentChunkSize = 0;
-      }
+          chunkPath = new Path(dictionaryPathBase, DICTIONARY_FILE + chunkIndex);
+          chunkPaths.add(chunkPath);
 
-      Writable key = record.getFirst();
-      int fieldSize = DICTIONARY_BYTE_OVERHEAD + key.toString().length() * 2 + Integer.SIZE / 8;
-      currentChunkSize += fieldSize;
-      dictWriter.append(key, new IntWritable(i++));
+          dictWriter = new SequenceFile.Writer(fs, conf, chunkPath, Text.class, IntWritable.class);
+          currentChunkSize = 0;
+        }
+
+        Writable key = record.getFirst();
+        int fieldSize = DICTIONARY_BYTE_OVERHEAD + key.toString().length() * 2 + Integer.SIZE / 8;
+        currentChunkSize += fieldSize;
+        dictWriter.append(key, new IntWritable(i++));
+      }
+      maxTermDimension[0] = i;
+    } finally {
+      Closeables.closeQuietly(dictWriter);
     }
-    maxTermDimension[0] = i;
-    dictWriter.close();
     
     return chunkPaths;
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/CollocMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/CollocMapper.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/CollocMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/CollocMapper.java Sat Jun  4 08:42:57 2011
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.vectorizer.collocations.llr;
 
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Mapper;
@@ -90,79 +91,82 @@ public class CollocMapper extends Mapper
   protected void map(Text key, StringTuple value, final Context context) throws IOException, InterruptedException {
 
     ShingleFilter sf = new ShingleFilter(new IteratorTokenStream(value.getEntries().iterator()), maxShingleSize);
-    int count = 0; // ngram count
 
-    OpenObjectIntHashMap<String> ngrams =
-            new OpenObjectIntHashMap<String>(value.getEntries().size() * (maxShingleSize - 1));
-    OpenObjectIntHashMap<String> unigrams = new OpenObjectIntHashMap<String>(value.getEntries().size());
-
-    do {
-      String term = sf.getAttribute(CharTermAttribute.class).toString();
-      String type = sf.getAttribute(TypeAttribute.class).type();
-      if ("shingle".equals(type)) {
-        count++;
-        ngrams.adjustOrPutValue(term, 1, 1);
-      } else if (emitUnigrams && term.length() > 0) { // unigram
-        unigrams.adjustOrPutValue(term, 1, 1);
-      }
-    } while (sf.incrementToken());
-
-    final GramKey gramKey = new GramKey();
-
-    ngrams.forEachPair(new ObjectIntProcedure<String>() {
-      @Override
-      public boolean apply(String term, int frequency) {
-        // obtain components, the leading (n-1)gram and the trailing unigram.
-        int i = term.lastIndexOf(' '); // TODO: fix for non-whitespace delimited languages.
-        if (i != -1) { // bigram, trigram etc
+    try {
+      int count = 0; // ngram count
 
-          try {
-            Gram ngram = new Gram(term, frequency, Gram.Type.NGRAM);
-            Gram head = new Gram(term.substring(0, i), frequency, Gram.Type.HEAD);
-            Gram tail = new Gram(term.substring(i + 1), frequency, Gram.Type.TAIL);
-
-            gramKey.set(head, EMPTY);
-            context.write(gramKey, head);
-
-            gramKey.set(head, ngram.getBytes());
-            context.write(gramKey, ngram);
+      OpenObjectIntHashMap<String> ngrams =
+              new OpenObjectIntHashMap<String>(value.getEntries().size() * (maxShingleSize - 1));
+      OpenObjectIntHashMap<String> unigrams = new OpenObjectIntHashMap<String>(value.getEntries().size());
+
+      do {
+        String term = sf.getAttribute(CharTermAttribute.class).toString();
+        String type = sf.getAttribute(TypeAttribute.class).type();
+        if ("shingle".equals(type)) {
+          count++;
+          ngrams.adjustOrPutValue(term, 1, 1);
+        } else if (emitUnigrams && term.length() > 0) { // unigram
+          unigrams.adjustOrPutValue(term, 1, 1);
+        }
+      } while (sf.incrementToken());
 
-            gramKey.set(tail, EMPTY);
-            context.write(gramKey, tail);
+      final GramKey gramKey = new GramKey();
 
-            gramKey.set(tail, ngram.getBytes());
-            context.write(gramKey, ngram);
+      ngrams.forEachPair(new ObjectIntProcedure<String>() {
+        @Override
+        public boolean apply(String term, int frequency) {
+          // obtain components, the leading (n-1)gram and the trailing unigram.
+          int i = term.lastIndexOf(' '); // TODO: fix for non-whitespace delimited languages.
+          if (i != -1) { // bigram, trigram etc
+
+            try {
+              Gram ngram = new Gram(term, frequency, Gram.Type.NGRAM);
+              Gram head = new Gram(term.substring(0, i), frequency, Gram.Type.HEAD);
+              Gram tail = new Gram(term.substring(i + 1), frequency, Gram.Type.TAIL);
+
+              gramKey.set(head, EMPTY);
+              context.write(gramKey, head);
+
+              gramKey.set(head, ngram.getBytes());
+              context.write(gramKey, ngram);
+
+              gramKey.set(tail, EMPTY);
+              context.write(gramKey, tail);
+
+              gramKey.set(tail, ngram.getBytes());
+              context.write(gramKey, ngram);
+
+            } catch (IOException e) {
+              throw new IllegalStateException(e);
+            } catch (InterruptedException e) {
+              throw new IllegalStateException(e);
+            }
+          }
+          return true;
+        }
+      });
 
+      unigrams.forEachPair(new ObjectIntProcedure<String>() {
+        @Override
+        public boolean apply(String term, int frequency) {
+          try {
+            Gram unigram = new Gram(term, frequency, Gram.Type.UNIGRAM);
+            gramKey.set(unigram, EMPTY);
+            context.write(gramKey, unigram);
           } catch (IOException e) {
             throw new IllegalStateException(e);
           } catch (InterruptedException e) {
             throw new IllegalStateException(e);
           }
+          return true;
         }
-        return true;
-      }
-    });
-
-    unigrams.forEachPair(new ObjectIntProcedure<String>() {
-      @Override
-      public boolean apply(String term, int frequency) {
-        try {
-          Gram unigram = new Gram(term, frequency, Gram.Type.UNIGRAM);
-          gramKey.set(unigram, EMPTY);
-          context.write(gramKey, unigram);
-        } catch (IOException e) {
-          throw new IllegalStateException(e);
-        } catch (InterruptedException e) {
-          throw new IllegalStateException(e);
-        }
-        return true;
-      }
-    });
+      });
 
-    context.getCounter(Count.NGRAM_TOTAL).increment(count);
-
-    sf.end();
-    sf.close();
+      context.getCounter(Count.NGRAM_TOTAL).increment(count);
+      sf.end();
+    } finally {
+      Closeables.closeQuietly(sf);
+    }
   }
 
   @Override

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TFPartialVectorReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TFPartialVectorReducer.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TFPartialVectorReducer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TFPartialVectorReducer.java Sat Jun  4 08:42:57 2011
@@ -18,6 +18,7 @@
 package org.apache.mahout.vectorizer.term;
 
 import com.google.common.base.Preconditions;
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.Path;
@@ -72,17 +73,19 @@ public class TFPartialVectorReducer exte
 
     if (maxNGramSize >= 2) {
       ShingleFilter sf = new ShingleFilter(new IteratorTokenStream(value.getEntries().iterator()), maxNGramSize);
-
-      do {
-        String term = (sf.getAttribute(CharTermAttribute.class)).toString();
-        if (term.length() > 0 && dictionary.containsKey(term)) { // ngram
-          int termId = dictionary.get(term);
-          vector.setQuick(termId, vector.getQuick(termId) + 1);
-        }
-      } while (sf.incrementToken());
-
-      sf.end();
-      sf.close();
+      try {
+        do {
+          String term = (sf.getAttribute(CharTermAttribute.class)).toString();
+          if (term.length() > 0 && dictionary.containsKey(term)) { // ngram
+            int termId = dictionary.get(term);
+            vector.setQuick(termId, vector.getQuick(termId) + 1);
+          }
+        } while (sf.incrementToken());
+
+        sf.end();
+      } finally {
+        Closeables.closeQuietly(sf);
+      }
     } else {
       for (String term : value.getEntries()) {
         if (term.length() > 0 && dictionary.containsKey(term)) { // unigram

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFConverter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFConverter.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFConverter.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFConverter.java Sat Jun  4 08:42:57 2011
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import com.google.common.base.Preconditions;
+import com.google.common.io.Closeables;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.FileSystem;
@@ -207,45 +208,48 @@ public final class TFIDFConverter {
     SequenceFile.Writer freqWriter =
       new SequenceFile.Writer(fs, conf, chunkPath, IntWritable.class, LongWritable.class);
 
-    long currentChunkSize = 0;
-    long featureCount = 0;
-    long vectorCount = Long.MAX_VALUE;
-    Path filesPattern = new Path(featureCountPath, OUTPUT_FILES_PATTERN);
-    for (Pair<IntWritable,LongWritable> record
-         : new SequenceFileDirIterable<IntWritable,LongWritable>(filesPattern,
-                                                                 PathType.GLOB,
-                                                                 null,
-                                                                 null,
-                                                                 true,
-                                                                 conf)) {
-
-      if (currentChunkSize > chunkSizeLimit) {
-        freqWriter.close();
-        chunkIndex++;
+    try {
+      long currentChunkSize = 0;
+      long featureCount = 0;
+      long vectorCount = Long.MAX_VALUE;
+      Path filesPattern = new Path(featureCountPath, OUTPUT_FILES_PATTERN);
+      for (Pair<IntWritable,LongWritable> record
+           : new SequenceFileDirIterable<IntWritable,LongWritable>(filesPattern,
+                                                                   PathType.GLOB,
+                                                                   null,
+                                                                   null,
+                                                                   true,
+                                                                   conf)) {
+
+        if (currentChunkSize > chunkSizeLimit) {
+          Closeables.closeQuietly(freqWriter);
+          chunkIndex++;
+
+          chunkPath = new Path(dictionaryPathBase, FREQUENCY_FILE + chunkIndex);
+          chunkPaths.add(chunkPath);
+
+          freqWriter = new SequenceFile.Writer(fs, conf, chunkPath, IntWritable.class, LongWritable.class);
+          currentChunkSize = 0;
+        }
+
+        int fieldSize = SEQUENCEFILE_BYTE_OVERHEAD + Integer.SIZE / 8 + Long.SIZE / 8;
+        currentChunkSize += fieldSize;
+        IntWritable key = record.getFirst();
+        LongWritable value = record.getSecond();
+        if (key.get() >= 0) {
+          freqWriter.append(key, value);
+        } else if (key.get() == -1) {
+          vectorCount = value.get();
+        }
+        featureCount = Math.max(key.get(), featureCount);
 
-        chunkPath = new Path(dictionaryPathBase, FREQUENCY_FILE + chunkIndex);
-        chunkPaths.add(chunkPath);
-
-        freqWriter = new SequenceFile.Writer(fs, conf, chunkPath, IntWritable.class, LongWritable.class);
-        currentChunkSize = 0;
-      }
-
-      int fieldSize = SEQUENCEFILE_BYTE_OVERHEAD + Integer.SIZE / 8 + Long.SIZE / 8;
-      currentChunkSize += fieldSize;
-      IntWritable key = record.getFirst();
-      LongWritable value = record.getSecond();
-      if (key.get() >= 0) {
-        freqWriter.append(key, value);
-      } else if (key.get() == -1) {
-        vectorCount = value.get();
       }
-      featureCount = Math.max(key.get(), featureCount);
-
+      featureCount++;
+      Long[] counts = {featureCount, vectorCount};
+      return new Pair<Long[], List<Path>>(counts, chunkPaths);
+    } finally {
+      Closeables.closeQuietly(freqWriter);
     }
-    featureCount++;
-    freqWriter.close();
-    Long[] counts = {featureCount, vectorCount};
-    return new Pair<Long[], List<Path>>(counts, chunkPaths);
   }
 
   /**

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/TasteTestCase.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/TasteTestCase.java?rev=1131350&r1=1131349&r2=1131350&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/TasteTestCase.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/TasteTestCase.java Sat Jun  4 08:42:57 2011
@@ -18,6 +18,7 @@
 package org.apache.mahout.cf.taste.impl;
 
 import com.google.common.base.Charsets;
+import com.google.common.io.Closeables;
 import org.apache.mahout.cf.taste.impl.common.FastByIDMap;
 import org.apache.mahout.common.MahoutTestCase;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
@@ -80,7 +81,7 @@ public abstract class TasteTestCase exte
         writer.println(line);
       }
     } finally {
-      writer.close();
+      Closeables.closeQuietly(writer);
     }
   }
 }



Mime
View raw message