use Closeable interface in IOUtils

This commit is contained in:
Hannes Janetzek
2013-09-20 13:50:11 +02:00
parent eab0f5e87a
commit 43de62f4bc
2 changed files with 66 additions and 18 deletions

View File

@@ -16,44 +16,33 @@ package org.oscim.utils;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.oscim.backend.Log;
/**
* A utility class with IO-specific helper methods.
*/
public final class IOUtils {
private static final Logger LOGGER = Logger.getLogger(IOUtils.class.getName());
/**
* Invokes the {@link Closeable#close()} method on the given object. If an {@link IOException} occurs during the
* Invokes the {@link Closeable#close()} method on the given object. If an
* {@link IOException} occurs during the
* method call, it will be caught and logged on level {@link Level#WARNING}.
*
*
* @param closeable
* the data source which should be closed (may be null).
*/
public static void closeQuietly(InputStream closeable) {
public static void closeQuietly(Closeable closeable) {
try {
if (closeable != null) {
closeable.close();
}
} catch (IOException e) {
LOGGER.log(Level.FINE, e.getMessage(), e);
Log.d(IOUtils.class.getName(), e.getMessage() + " " + e);
}
}
public static void closeQuietly(OutputStream closeable) {
try {
if (closeable != null) {
closeable.close();
}
} catch (IOException e) {
LOGGER.log(Level.FINE, e.getMessage(), e);
}
}
private IOUtils() {
throw new IllegalStateException();
}
}