You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/08/27 18:52:01 UTC

svn commit: r1162402 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ lucene/contrib/facet/src/test/org/apache/lucene/facet/search/ lucene/contrib/facet/src/test/org/apach...

Author: mikemccand
Date: Sat Aug 27 16:52:00 2011
New Revision: 1162402

URL: http://svn.apache.org/viewvc?rev=1162402&view=rev
Log:
LUCENE-3405: rename IOUtils.close methods

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java
    lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java
    lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java
    lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsReader.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsDocsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsFieldsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsPositionsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/NormsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentMerger.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosReader.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/IOUtils.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermVectors.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java Sat Aug 27 16:52:00 2011
@@ -96,7 +96,7 @@ public class TestMultipleCategoryLists e
     searcher.close();
     iw.close();
     tw.close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   @Test
@@ -137,7 +137,7 @@ public class TestMultipleCategoryLists e
     searcher.close();
     iw.close();
     tw.close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   @Test
@@ -181,7 +181,7 @@ public class TestMultipleCategoryLists e
     searcher.close();
     iw.close();
     tw.close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException {
@@ -229,7 +229,7 @@ public class TestMultipleCategoryLists e
     searcher.close();
     iw.close();
     tw.close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   @Test
@@ -274,7 +274,7 @@ public class TestMultipleCategoryLists e
     searcher.close();
     iw.close();
     tw.close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   private Directory[][] getDirs() throws IOException {

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java Sat Aug 27 16:52:00 2011
@@ -109,7 +109,7 @@ public class TestTotalFacetCounts extend
       ++partition;
     }
     readers[0].close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
     tmpFile.delete();
   }
 

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java Sat Aug 27 16:52:00 2011
@@ -339,7 +339,7 @@ public class TestTotalFacetCountsCache e
     readers[0].close();
     r2.close();
     outputFile.delete();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   private int assertReadFromDisc(TotalFacetCounts totalCounts, int prevGen, String errMsg) {
@@ -405,7 +405,7 @@ public class TestTotalFacetCountsCache e
     outputFile.delete();
     writers[0].close();
     readers[0].close();
-    IOUtils.closeSafely(false, dirs[0]);
+    IOUtils.close(dirs[0]);
   }
 
   /**
@@ -535,7 +535,7 @@ public class TestTotalFacetCountsCache e
     readers[0].close();
     readers[1].close();
     for (Directory[] dirset : dirs) {
-      IOUtils.closeSafely(false, dirset);
+      IOUtils.close(dirset);
     }
   }
 

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java Sat Aug 27 16:52:00 2011
@@ -247,8 +247,8 @@ public class TestAddTaxonomies extends L
     }
 
     main.close();
-    IOUtils.closeSafely(false, dirs);
-    IOUtils.closeSafely(false, copydirs);
+    IOUtils.close(dirs);
+    IOUtils.close(copydirs);
   }
 
 }

Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java Sat Aug 27 16:52:00 2011
@@ -112,7 +112,11 @@ public class PKIndexSplitter {
       createIndex(config2, dir2, reader, docsInFirstIndex, true);
       success = true;
     } finally {
-      IOUtils.closeSafely(!success, reader);
+      if (success) {
+        IOUtils.close(reader);
+      } else {
+        IOUtils.closeWhileHandlingException(reader);
+      }
     }
   }
   
@@ -123,7 +127,11 @@ public class PKIndexSplitter {
       w.addIndexes(new DocumentFilteredIndexReader(reader, preserveFilter, negateFilter));
       success = true;
     } finally {
-      IOUtils.closeSafely(!success, w);
+      if (success) {
+        IOUtils.close(w);
+      } else {
+        IOUtils.closeWhileHandlingException(w);
+      }
     }
   }
     

Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java Sat Aug 27 16:52:00 2011
@@ -318,7 +318,7 @@ public class NRTCachingDirectory extends
         in = cache.openInput(fileName);
         in.copyBytes(out, in.length());
       } finally {
-        IOUtils.closeSafely(false, in, out);
+        IOUtils.close(in, out);
       }
       synchronized(this) {
         cache.deleteFile(fileName);

Modified: lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java Sat Aug 27 16:52:00 2011
@@ -512,7 +512,7 @@ public class FSTLookup extends Lookup {
       this.automaton = new FST<Object>(new InputStreamDataInput(is), NoOutputs.getSingleton());
       cacheRootArcs();
     } finally {
-      IOUtils.closeSafely(false, is);
+      IOUtils.close(is);
     }
     return true;
   }
@@ -534,7 +534,7 @@ public class FSTLookup extends Lookup {
     try {
       this.automaton.save(new OutputStreamDataOutput(os));
     } finally {
-      IOUtils.closeSafely(false, os);
+      IOUtils.close(os);
     }
 
     return true;

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java Sat Aug 27 16:52:00 2011
@@ -219,7 +219,7 @@ public final class CompoundFileWriter {
         } catch (IOException e) {
           priorException = e;
         } finally {
-          IOUtils.closeSafely(priorException, os);
+          IOUtils.closeWhileHandlingException(priorException, os);
         }
     }
 

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsReader.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsReader.java Sat Aug 27 16:52:00 2011
@@ -17,6 +17,7 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.zip.DataFormatException;
@@ -35,13 +36,14 @@ import org.apache.lucene.store.BufferedI
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.util.CloseableThreadLocal;
+import org.apache.lucene.util.IOUtils;
 
 /**
  * Class responsible for access to stored document fields.
  * <p/>
  * It uses &lt;segment&gt;.fdt and &lt;segment&gt;.fdx; files.
  */
-final class FieldsReader implements Cloneable {
+final class FieldsReader implements Cloneable, Closeable {
   private final FieldInfos fieldInfos;
 
   // The main fieldStream, used only for cloning.
@@ -197,23 +199,13 @@ final class FieldsReader implements Clon
    *
    * @throws IOException
    */
-  final void close() throws IOException {
+  public final void close() throws IOException {
     if (!closed) {
-      if (fieldsStream != null) {
-        fieldsStream.close();
-      }
       if (isOriginal) {
-        if (cloneableFieldsStream != null) {
-          cloneableFieldsStream.close();
-        }
-        if (cloneableIndexStream != null) {
-          cloneableIndexStream.close();
-        }
-      }
-      if (indexStream != null) {
-        indexStream.close();
+        IOUtils.close(fieldsStream, indexStream, fieldsStreamTL, cloneableFieldsStream, cloneableIndexStream);
+      } else {
+        IOUtils.close(fieldsStream, indexStream, fieldsStreamTL);
       }
-      fieldsStreamTL.close();
       closed = true;
     }
   }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FieldsWriter.java Sat Aug 27 16:52:00 2011
@@ -124,7 +124,7 @@ final class FieldsWriter {
   void close() throws IOException {
     if (directory != null) {
       try {
-        IOUtils.closeSafely(false, fieldsStream, indexStream);
+        IOUtils.close(fieldsStream, indexStream);
       } finally {
         fieldsStream = indexStream = null;
       }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsDocsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsDocsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsDocsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsDocsWriter.java Sat Aug 27 16:52:00 2011
@@ -58,7 +58,7 @@ final class FormatPostingsDocsWriter ext
       success = true;
     } finally {
       if (!success) {
-        IOUtils.closeSafely(true, out);
+        IOUtils.closeWhileHandlingException(out);
       }
     }
   }
@@ -131,6 +131,6 @@ final class FormatPostingsDocsWriter ext
   }
 
   public void close() throws IOException {
-    IOUtils.closeSafely(false, out, posWriter);
+    IOUtils.close(out, posWriter);
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsFieldsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsFieldsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsFieldsWriter.java Sat Aug 27 16:52:00 2011
@@ -52,7 +52,7 @@ final class FormatPostingsFieldsWriter e
       success = true;
     } finally {
       if (!success) {
-        IOUtils.closeSafely(true, termsOut, termsWriter);
+        IOUtils.closeWhileHandlingException(termsOut, termsWriter);
       }
     }
   }
@@ -67,6 +67,6 @@ final class FormatPostingsFieldsWriter e
   /** Called when we are done adding everything. */
   @Override
   void finish() throws IOException {
-    IOUtils.closeSafely(false, termsOut, termsWriter);
+    IOUtils.close(termsOut, termsWriter);
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsPositionsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsPositionsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsPositionsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/FormatPostingsPositionsWriter.java Sat Aug 27 16:52:00 2011
@@ -84,6 +84,6 @@ final class FormatPostingsPositionsWrite
   }
 
   public void close() throws IOException {
-    IOUtils.closeSafely(false, out);
+    IOUtils.close(out);
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/NormsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/NormsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/NormsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/NormsWriter.java Sat Aug 27 16:52:00 2011
@@ -168,7 +168,11 @@ final class NormsWriter extends Inverted
       }
       success = true;
     } finally {
-      IOUtils.closeSafely(!success, normsOut);
+      if (success) {
+        IOUtils.close(normsOut);
+      } else {
+        IOUtils.closeWhileHandlingException(normsOut);
+      }
     }
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java Sat Aug 27 16:52:00 2011
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.IOUtils;
 
 /** Holds core readers that are shared (unchanged) when
  * SegmentReader is cloned or reopened */
@@ -159,42 +160,9 @@ final class SegmentCoreReaders {
   synchronized void decRef() throws IOException {
 
     if (ref.decrementAndGet() == 0) {
-
-      // close everything, nothing is shared anymore with other readers
-      if (tis != null) {
-        tis.close();
-        // null so if an app hangs on to us we still free most ram
-        tis = null;
-      }
-      
-      if (tisNoIndex != null) {
-        tisNoIndex.close();
-      }
-      
-      if (freqStream != null) {
-        freqStream.close();
-      }
-
-      if (proxStream != null) {
-        proxStream.close();
-      }
-
-      if (termVectorsReaderOrig != null) {
-        termVectorsReaderOrig.close();
-      }
-
-      if (fieldsReaderOrig != null) {
-        fieldsReaderOrig.close();
-      }
-
-      if (cfsReader != null) {
-        cfsReader.close();
-      }
-
-      if (storeCFSReader != null) {
-        storeCFSReader.close();
-      }
-
+      IOUtils.close(tis, tisNoIndex, freqStream, proxStream, termVectorsReaderOrig,
+                    fieldsReaderOrig, cfsReader, storeCFSReader);
+      tis = null;
       // Now, notify any ReaderFinished listeners:
       if (owner != null) {
         owner.notifyReaderFinishedListeners();

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfos.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfos.java Sat Aug 27 16:52:00 2011
@@ -401,7 +401,7 @@ public final class SegmentInfos implemen
       if (!success) {
         // We hit an exception above; try to close the file
         // but suppress any exception:
-        IOUtils.closeSafely(true, segnOutput);
+        IOUtils.closeWhileHandlingException(segnOutput);
         try {
           // Try not to leave a truncated segments_N file in
           // the index:

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentMerger.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentMerger.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentMerger.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentMerger.java Sat Aug 27 16:52:00 2011
@@ -578,6 +578,7 @@ final class SegmentMerger {
       if (smi.dirPayloadProcessor != null) {
         payloadProcessor = smi.dirPayloadProcessor.getProcessor(smi.term);
       }
+
       while (postings.next()) {
         df++;
         int doc = postings.doc();
@@ -660,7 +661,11 @@ final class SegmentMerger {
       }
       success = true;
     } finally {
-      IOUtils.closeSafely(!success, output);
+      if (success) {
+        IOUtils.close(output);
+      } else {
+        IOUtils.closeWhileHandlingException(output);
+      }
     }
   }
 

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosReader.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosReader.java Sat Aug 27 16:52:00 2011
@@ -17,6 +17,7 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.lucene.store.Directory;
@@ -27,7 +28,7 @@ import org.apache.lucene.util.CloseableT
  * Directory.  Pairs are accessed either by Term or by ordinal position the
  * set.  */
 
-final class TermInfosReader {
+final class TermInfosReader implements Closeable {
   private final Directory directory;
   private final String segment;
   private final FieldInfos fieldInfos;
@@ -158,7 +159,7 @@ final class TermInfosReader {
     return origEnum.maxSkipLevels;
   }
 
-  final void close() throws IOException {
+  public final void close() throws IOException {
     if (origEnum != null)
       origEnum.close();
     threadResources.close();

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermInfosWriter.java Sat Aug 27 16:52:00 2011
@@ -92,7 +92,7 @@ final class TermInfosWriter implements C
       success = true;
     } finally {
       if (!success) {
-        IOUtils.closeSafely(true, output, other);
+        IOUtils.closeWhileHandlingException(output, other);
       }
     }
   }
@@ -119,7 +119,7 @@ final class TermInfosWriter implements C
       success = true;
     } finally {
       if (!success) {
-        IOUtils.closeSafely(true, output);
+        IOUtils.closeWhileHandlingException(output);
       }
     }
   }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java Sat Aug 27 16:52:00 2011
@@ -17,15 +17,17 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Arrays;
+
 import org.apache.lucene.store.BufferedIndexInput;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.IOUtils;
 
-import java.io.IOException;
-import java.util.Arrays;
-
-class TermVectorsReader implements Cloneable {
+class TermVectorsReader implements Cloneable, Closeable {
 
   // NOTE: if you make a new format, it must be larger than
   // the current format
@@ -200,14 +202,8 @@ class TermVectorsReader implements Clone
     return format;
   }
 
-  void close() throws IOException {
-    // make all effort to close up. Keep the first exception
-    // and throw it as a new one.
-    IOException keep = null;
-    if (tvx != null) try { tvx.close(); } catch (IOException e) { keep = e; }
-    if (tvd != null) try { tvd.close(); } catch (IOException e) { if (keep == null) keep = e; }
-    if (tvf  != null) try {  tvf.close(); } catch (IOException e) { if (keep == null) keep = e; }
-    if (keep != null) throw (IOException) keep.fillInStackTrace();
+  public void close() throws IOException {
+    IOUtils.close(tvx, tvd, tvf);
   }
 
   /**

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java Sat Aug 27 16:52:00 2011
@@ -53,7 +53,7 @@ final class TermVectorsTermsWriter exten
     if (tvx != null) {
       // At least one doc in this run had term vectors enabled
       fill(state.numDocs);
-      IOUtils.closeSafely(false, tvx, tvf, tvd);
+      IOUtils.close(tvx, tvf, tvd);
       tvx = tvd = tvf = null;
       assert state.segmentName != null;
       String idxName = IndexFileNames.segmentFileName(state.segmentName, IndexFileNames.VECTORS_INDEX_EXTENSION);
@@ -129,7 +129,7 @@ final class TermVectorsTermsWriter exten
         success = true;
       } finally {
         if (!success) {
-          IOUtils.closeSafely(true, tvx, tvd, tvf);
+          IOUtils.closeWhileHandlingException(tvx, tvd, tvf);
         }
       }
       lastDocID = 0;
@@ -176,7 +176,7 @@ final class TermVectorsTermsWriter exten
   public void abort() {
     hasVectors = false;
     try {
-      IOUtils.closeSafely(true, tvx, tvd, tvf);
+      IOUtils.closeWhileHandlingException(tvx, tvd, tvf);
     } catch (IOException e) {
       // cannot happen since we suppress exceptions
       throw new RuntimeException(e);

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java Sat Aug 27 16:52:00 2011
@@ -46,7 +46,7 @@ final class TermVectorsWriter {
       success = true;
     } finally {
       if (!success) {
-        IOUtils.closeSafely(true, tvx, tvd, tvf);
+        IOUtils.closeWhileHandlingException(tvx, tvd, tvf);
       }
     }
 
@@ -201,6 +201,6 @@ final class TermVectorsWriter {
   final void close() throws IOException {
     // make an effort to close all streams we can but remember and re-throw
     // the first exception encountered in this process
-    IOUtils.closeSafely(false, tvx, tvd, tvf);
+    IOUtils.close(tvx, tvd, tvf);
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java Sat Aug 27 16:52:00 2011
@@ -235,7 +235,7 @@ public abstract class Directory implemen
     } catch (IOException ioe) {
       priorException = ioe;
     } finally {
-      IOUtils.closeSafely(priorException, os, is);
+      IOUtils.closeWhileHandlingException(priorException, os, is);
     }
   }
 

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/IOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/IOUtils.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/IOUtils.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/IOUtils.java Sat Aug 27 16:52:00 2011
@@ -49,7 +49,7 @@ public final class IOUtils {
    * @param priorException  <tt>null</tt> or an exception that will be rethrown after method completion
    * @param objects         objects to call <tt>close()</tt> on
    */
-  public static <E extends Exception> void closeSafely(E priorException, Closeable... objects) throws E, IOException {
+  public static <E extends Exception> void closeWhileHandlingException(E priorException, Closeable... objects) throws E, IOException {
     Throwable th = null;
 
     for (Closeable object : objects) {
@@ -75,8 +75,8 @@ public final class IOUtils {
     }
   }
 
-  /** @see #closeSafely(Exception, Closeable...) */
-  public static <E extends Exception> void closeSafely(E priorException, Iterable<Closeable> objects) throws E, IOException {
+  /** @see #closeWhileHandlingException(Exception, Closeable...) */
+  public static <E extends Exception> void closeWhileHandlingException(E priorException, Iterable<Closeable> objects) throws E, IOException {
     Throwable th = null;
 
     for (Closeable object : objects) {
@@ -103,18 +103,16 @@ public final class IOUtils {
   }
 
   /**
-   * Closes all given <tt>Closeable</tt>s, suppressing all thrown exceptions.
-   * Some of the <tt>Closeable</tt>s may be null, they are ignored. After
-   * everything is closed, and if {@code suppressExceptions} is {@code false},
-   * method either throws the first of suppressed exceptions, or completes
-   * normally.
+   * Closes all given <tt>Closeable</tt>s.  Some of the
+   * <tt>Closeable</tt>s may be null; they are
+   * ignored.  After everything is closed, the method either
+   * throws the first exception it hit while closing, or
+   * completes normally if there were no exceptions.
    * 
-   * @param suppressExceptions
-   *          if true then exceptions that occur during close() are suppressed
    * @param objects
    *          objects to call <tt>close()</tt> on
    */
-  public static void closeSafely(boolean suppressExceptions, Closeable... objects) throws IOException {
+  public static void close(Closeable... objects) throws IOException {
     Throwable th = null;
 
     for (Closeable object : objects) {
@@ -124,12 +122,13 @@ public final class IOUtils {
         }
       } catch (Throwable t) {
         addSuppressed(th, t);
-        if (th == null)
+        if (th == null) {
           th = t;
+        }
       }
     }
 
-    if (th != null && !suppressExceptions) {
+    if (th != null) {
       if (th instanceof IOException) throw (IOException) th;
       if (th instanceof RuntimeException) throw (RuntimeException) th;
       if (th instanceof Error) throw (Error) th;
@@ -138,9 +137,9 @@ public final class IOUtils {
   }
   
   /**
-   * @see #closeSafely(boolean, Closeable...)
+   * @see #close(Closeable...)
    */
-  public static void closeSafely(boolean suppressExceptions, Iterable<? extends Closeable> objects) throws IOException {
+  public static void close(Iterable<? extends Closeable> objects) throws IOException {
     Throwable th = null;
 
     for (Closeable object : objects) {
@@ -150,18 +149,51 @@ public final class IOUtils {
         }
       } catch (Throwable t) {
         addSuppressed(th, t);
-        if (th == null)
+        if (th == null) {
           th = t;
+        }
       }
     }
 
-    if (th != null && !suppressExceptions) {
+    if (th != null) {
       if (th instanceof IOException) throw (IOException) th;
       if (th instanceof RuntimeException) throw (RuntimeException) th;
       if (th instanceof Error) throw (Error) th;
       throw new RuntimeException(th);
     }
   }
+
+  /**
+   * Closes all given <tt>Closeable</tt>s, suppressing all thrown exceptions.
+   * Some of the <tt>Closeable</tt>s may be null, they are ignored.
+   * 
+   * @param objects
+   *          objects to call <tt>close()</tt> on
+   */
+  public static void closeWhileHandlingException(Closeable... objects) throws IOException {
+    for (Closeable object : objects) {
+      try {
+        if (object != null) {
+          object.close();
+        }
+      } catch (Throwable t) {
+      }
+    }
+  }
+  
+  /**
+   * @see #closeWhileHandlingException(Closeable...)
+   */
+  public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) throws IOException {
+    for (Closeable object : objects) {
+      try {
+        if (object != null) {
+          object.close();
+        }
+      } catch (Throwable t) {
+      }
+    }
+  }
   
   /** This reflected {@link Method} is {@code null} before Java 7 */
   private static final Method SUPPRESS_METHOD;

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermVectors.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermVectors.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermVectors.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermVectors.java Sat Aug 27 16:52:00 2011
@@ -505,7 +505,7 @@ public class TestTermVectors extends Luc
 
     verifyIndex(target);
 
-    IOUtils.closeSafely(false, target, input[0], input[1]);
+    IOUtils.close(target, input[0], input[1]);
   }
   
   public void testOptimizeAddIndexesReader() throws Exception {
@@ -526,7 +526,7 @@ public class TestTermVectors extends Luc
     writer.close();
     
     verifyIndex(target);
-    IOUtils.closeSafely(false, target, input[0], input[1]);
+    IOUtils.close(target, input[0], input[1]);
   }
   
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java Sat Aug 27 16:52:00 2011
@@ -59,7 +59,7 @@ public class TestIOUtils extends LuceneT
     // test with prior exception
     try {
       final TestException t = new TestException();
-      IOUtils.closeSafely(t, new BrokenCloseable(1), new BrokenCloseable(2));
+      IOUtils.closeWhileHandlingException(t, new BrokenCloseable(1), new BrokenCloseable(2));
     } catch (TestException e1) {
       assertEquals("BASE-EXCEPTION", e1.getMessage());
       final StringWriter sw = new StringWriter();
@@ -83,7 +83,7 @@ public class TestIOUtils extends LuceneT
     
     // test without prior exception
     try {
-      IOUtils.closeSafely((TestException) null, new BrokenCloseable(1), new BrokenCloseable(2));
+      IOUtils.closeWhileHandlingException((TestException) null, new BrokenCloseable(1), new BrokenCloseable(2));
     } catch (TestException e1) {
       fail("TestException should not be thrown here");
     } catch (IOException e2) {

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=1162402&r1=1162401&r2=1162402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java Sat Aug 27 16:52:00 2011
@@ -239,7 +239,7 @@ public class CoreAdminHandler extends Re
             if (solrCore != null) solrCore.close();
           }
         }
-        if (readersToBeClosed != null) IOUtils.closeSafely(true, readersToBeClosed);
+        if (readersToBeClosed != null) IOUtils.closeWhileHandlingException(readersToBeClosed);
         core.close();
       }
     }