Added util class to handle I/O operations
This commit is contained in:
parent
8c2050f8f2
commit
df7cff28d4
2 changed files with 53 additions and 0 deletions
4
pom.xml
4
pom.xml
|
@ -47,6 +47,10 @@
|
|||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
49
src/main/java/com/rometools/utils/IO.java
Normal file
49
src/main/java/com/rometools/utils/IO.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue