Added util class to handle I/O operations

This commit is contained in:
Patrick Gotthard 2015-02-16 22:23:38 +01:00
parent 8c2050f8f2
commit df7cff28d4
2 changed files with 53 additions and 0 deletions

View file

@ -47,6 +47,10 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View file

@ -0,0 +1,49 @@
package com.rometools.utils;
import java.io.Closeable;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utility class to handle I/O operations.
*
* @author Patrick Gotthard
*
*/
public final class IO {
private static final Logger LOG = LoggerFactory.getLogger(IO.class);
private IO() {
}
/**
* Closes a {@link Closeable} object without suppressing a possible {@link IOException}.
*
* @param closeable The {@link Closeable} to close
* @throws IOException when the {@link Closeable} can't be closed
*/
public static void close(final Closeable closeable) throws IOException {
if (closeable != null) {
closeable.close();
}
}
/**
* Closes a {@link Closeable} object and suppresses a possible {@link IOException}.
*
* @param closeable The {@link Closeable} to close
*/
public static void closeQuietly(final Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (final IOException e) {
LOG.warn("Unable to close resource", e);
}
}
}
}