add closeQuietly() method
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ffee3c2c50
commit
326db9a72e
@ -18,6 +18,7 @@
|
|||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -27,6 +28,10 @@ import java.util.zip.CRC32;
|
|||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
|
|
||||||
public final class IOUtils {
|
public final class IOUtils {
|
||||||
|
|
||||||
|
private static final POILogger logger = POILogFactory
|
||||||
|
.getLogger( IOUtils.class );
|
||||||
|
|
||||||
private IOUtils() {
|
private IOUtils() {
|
||||||
// no instances of this class
|
// no instances of this class
|
||||||
}
|
}
|
||||||
@ -137,4 +142,24 @@ public final class IOUtils {
|
|||||||
sum.update(data, 0, data.length);
|
sum.update(data, 0, data.length);
|
||||||
return sum.getValue();
|
return sum.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quietly (no exceptions) close Closable resource. In case of error it will
|
||||||
|
* be printed to {@link IOUtils} class logger.
|
||||||
|
*
|
||||||
|
* @param closeable
|
||||||
|
* resource to close
|
||||||
|
*/
|
||||||
|
public static void closeQuietly( final Closeable closeable )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
closeable.close();
|
||||||
|
}
|
||||||
|
catch ( Exception exc )
|
||||||
|
{
|
||||||
|
logger.log( POILogger.ERROR, "Unable to close resource: " + exc,
|
||||||
|
exc );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user