commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1202515 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/IOUtils.java
Date Wed, 16 Nov 2011 02:52:04 GMT
Author: sebb
Date: Wed Nov 16 02:52:04 2011
New Revision: 1202515

URL: http://svn.apache.org/viewvc?rev=1202515&view=rev
Log:
IO-292 IOUtils.closeQuietly() should take a ServerSocket as a parameter

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

Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1202515&r1=1202514&r2=1202515&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Wed Nov 16 02:52:04 2011
@@ -40,6 +40,9 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="2.2" date="TBA">
+      <action dev="sebb" type="add" issue="IO-292" due-to="sebb">
+        IOUtils.closeQuietly() should take a ServerSocket as a parameter
+      </action>        
       <action dev="sebb" type="add" issue="IO-290" due-to="sebb">
         Add read/readFully methods to IOUtils
       </action>        

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java?rev=1202515&r1=1202514&r2=1202515&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java Wed Nov 16 02:52:04
2011
@@ -31,6 +31,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
 import java.net.URL;
@@ -319,6 +320,39 @@ public class IOUtils {
     }
 
     /**
+     * Unconditionally close a <code>ServerSocket</code>.
+     * <p>
+     * Equivalent to {@link ServerSocket#close()}, except any exceptions will be ignored.
+     * This is typically used in finally blocks.
+     * <p>
+     * Example code:
+     * <pre>
+     *   ServerSocket socket = null;
+     *   try {
+     *       socket = new ServerSocket();
+     *       // process socket
+     *       socket.close();
+     *   } catch (Exception e) {
+     *       // error handling
+     *   } finally {
+     *       IOUtils.closeQuietly(socket);
+     *   }
+     * </pre>
+     *
+     * @param sock the ServerSocket to close, may be null or already closed
+     * @since 2.2
+     */
+    public static void closeQuietly(ServerSocket 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