public final class IOUtils extends Object
I/O-related utility methods that don't have a better home.
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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) |
public static void quietClose(ResultSet closeable)
public static void quietClose(Statement closeable)
public static void quietClose(Connection closeable)
public static void quietClose(ResultSet resultSet, Statement statement, Connection connection)
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.resultSet
- ResultSet
to closestatement
- Statement
to closeconnection
- Connection
to closepublic static void close(Collection<? extends Closeable> closeables) throws IOException
closeables
(to prevent repeating close attempts), re-throw the
last one at the end. Helps resource scope management (e.g. compositions of
Closeable
s objects)
Typical pattern:
LinkedListcloseables = new LinkedList (); try { InputStream stream1 = new FileInputStream(...); closeables.addFirst(stream1); ... InputStream streamN = new FileInputStream(...); closeables.addFirst(streamN); ... } finally { IOUtils.close(closeables); }
closeables
- must be a modifiable collection of Closeable
sIOException
- the last exception (if any) of all closed resourcesCopyright © 2008–2017 The Apache Software Foundation. All rights reserved.