]> source.dussan.org Git - poi.git/commitdiff
add closeQuietly() method
authorSergey Vladimirov <sergey@apache.org>
Mon, 4 Jul 2011 19:50:01 +0000 (19:50 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 4 Jul 2011 19:50:01 +0000 (19:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142781 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/IOUtils.java

index 4812584898bf53340712510af623ad9a3bdcd637..4f18214c46da429d00944351274b8d1bb3a9c9e1 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.util;
 
 import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -27,6 +28,10 @@ import java.util.zip.CRC32;
 import java.util.zip.Checksum;
 
 public final class IOUtils {
+
+    private static final POILogger logger = POILogFactory
+            .getLogger( IOUtils.class );
+
        private IOUtils() {
                // no instances of this class
        }
@@ -137,4 +142,24 @@ public final class IOUtils {
         sum.update(data, 0, data.length);
         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 );
+        }
+    }
 }