org.apache.lucene.util
Class IOUtils

java.lang.Object
  extended by org.apache.lucene.util.IOUtils

public final class IOUtils
extends Object

NOTE: This API is for Lucene internal purposes only and might change in incompatible ways in the next release.

Method Summary
static void closeSafely(boolean suppressExceptions, Closeable... objects)
          Closes all given Closeables, suppressing all thrown exceptions.
static void closeSafely(boolean suppressExceptions, Iterable<? extends Closeable> objects)
           
static
<E extends Exception>
void
closeSafely(E priorException, Closeable... objects)
          Closes all given Closeables, suppressing all thrown exceptions.
static
<E extends Exception>
void
closeSafely(E priorException, Iterable<Closeable> objects)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

closeSafely

public static <E extends Exception> void closeSafely(E priorException,
                                                     Closeable... objects)
                        throws E extends Exception,
                               IOException

Closes all given Closeables, suppressing all thrown exceptions. Some of the Closeables may be null, they are ignored. After everything is closed, method either throws priorException, if one is supplied, or the first of suppressed exceptions, or completes normally.

Sample usage:

 Closeable resource1 = null, resource2 = null, resource3 = null;
 ExpectedException priorE = null;
 try {
   resource1 = ...; resource2 = ...; resource3 = ...; // Acquisition may throw ExpectedException
   ..do..stuff.. // May throw ExpectedException
 } catch (ExpectedException e) {
   priorE = e;
 } finally {
   closeSafely(priorE, resource1, resource2, resource3);
 }
 

Parameters:
priorException - null or an exception that will be rethrown after method completion
objects - objects to call close() on
Throws:
E extends Exception
IOException

closeSafely

public static <E extends Exception> void closeSafely(E priorException,
                                                     Iterable<Closeable> objects)
                        throws E extends Exception,
                               IOException
Throws:
E extends Exception
IOException
See Also:
closeSafely(Exception, Closeable...)

closeSafely

public static void closeSafely(boolean suppressExceptions,
                               Closeable... objects)
                        throws IOException
Closes all given Closeables, suppressing all thrown exceptions. Some of the Closeables may be null, they are ignored. After everything is closed, and if suppressExceptions is false, method either throws the first of suppressed exceptions, or completes normally.

Parameters:
suppressExceptions - if true then exceptions that occur during close() are suppressed
objects - objects to call close() on
Throws:
IOException

closeSafely

public static void closeSafely(boolean suppressExceptions,
                               Iterable<? extends Closeable> objects)
                        throws IOException
Throws:
IOException
See Also:
closeSafely(boolean, Closeable...)


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.