commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r920497 - /commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
Date Mon, 08 Mar 2010 20:36:39 GMT
Author: sebb
Date: Mon Mar  8 20:36:39 2010
New Revision: 920497

URL: http://svn.apache.org/viewvc?rev=920497&view=rev
Log:
IO-224 Add closeQuietly(Socket) to IOUtils

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java?rev=920497&r1=920496&r2=920497&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java Mon Mar  8 20:36:39
2010
@@ -31,6 +31,7 @@
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.net.Socket;
 import java.nio.channels.Channel;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -222,6 +223,24 @@
     }
 
     /**
+     * Unconditionally close a <code>Socket</code>.
+     * <p>
+     * Equivalent to {@link Socket#close()}, except any exceptions will be ignored.
+     * This is typically used in finally blocks.
+     *
+     * @param sock the Socket to close, may be null or already closed
+     */
+    public static void closeQuietly(Socket sock){
+        if (sock != null){
+            try {
+                sock.close();
+            } catch (IOException ioe) {
+                // ignored
+            }
+        }
+    }
+
+    /**
      * Fetches entire contents of an <code>InputStream</code> and represent
      * same data as result InputStream.
      * <p>



Mime
View raw message