org.apache.mahout.common
Class IOUtils

java.lang.Object
  extended by org.apache.mahout.common.IOUtils

public final class IOUtils
extends Object

I/O-related utility methods that don't have a better home.


Nested Class Summary
static class IOUtils.DeleteFileOnClose
          for temporary files, a file may be considered as a Closeable too, where file is wiped on close and thus the disk resource is released ('closed').
static class IOUtils.MultipleOutputsCloseableAdapter
          MultipleOutputs to closeable adapter.
 
Method Summary
static void close(Collection<? extends Closeable> closeables)
          make sure to close all sources, log all of the problems occurred, clear closeables (to prevent repeating close attempts), re-throw the last one at the end.
static void quietClose(Connection closeable)
           
static void quietClose(ResultSet closeable)
           
static void quietClose(ResultSet resultSet, Statement statement, Connection connection)
          Closes a ResultSet, Statement and Connection (if not null) and logs (but does not rethrow) any resulting SQLException.
static void quietClose(Statement closeable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

quietClose

public static void quietClose(ResultSet closeable)

quietClose

public static void quietClose(Statement closeable)

quietClose

public static void quietClose(Connection closeable)

quietClose

public static void quietClose(ResultSet resultSet,
                              Statement statement,
                              Connection connection)
Closes a ResultSet, Statement and Connection (if not null) and logs (but does not rethrow) any resulting SQLException. This is useful for cleaning up after a database query.

Parameters:
resultSet - ResultSet to close
statement - Statement to close
connection - Connection to close

close

public static void close(Collection<? extends Closeable> closeables)
                  throws IOException
make sure to close all sources, log all of the problems occurred, clear closeables (to prevent repeating close attempts), re-throw the last one at the end. Helps resource scope management (e.g. compositions of Closeables objects)

Typical pattern:

   LinkedList closeables = new LinkedList();
   try {
      InputStream stream1 = new FileInputStream(...);
      closeables.addFirst(stream1);
      ...
      InputStream streamN = new FileInputStream(...);
      closeables.addFirst(streamN);
      ...
   } finally {
      IOUtils.close(closeables);
   }
 

Parameters:
closeables - must be a modifiable collection of Closeables
Throws:
IOException - the last exception (if any) of all closed resources


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.