poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1142781 - /poi/trunk/src/java/org/apache/poi/util/IOUtils.java
Date Mon, 04 Jul 2011 19:50:01 GMT
Author: sergey
Date: Mon Jul  4 19:50:01 2011
New Revision: 1142781

URL: http://svn.apache.org/viewvc?rev=1142781&view=rev
Log:
add closeQuietly() method

Modified:
    poi/trunk/src/java/org/apache/poi/util/IOUtils.java

Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1142781&r1=1142780&r2=1142781&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Mon Jul  4 19:50:01 2011
@@ -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 );
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message