You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/03/08 21:36:39 UTC
svn commit: r920497 -
/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
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>