commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r962863 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/SocketClient.java
Date Sat, 10 Jul 2010 16:05:48 GMT
Author: sebb
Date: Sat Jul 10 16:05:48 2010
New Revision: 962863

URL: http://svn.apache.org/viewvc?rev=962863&view=rev
Log:
NET-283 - SocketClient should ensure input and output streams are closed

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/SocketClient.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/SocketClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/SocketClient.java?rev=962863&r1=962862&r2=962863&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/SocketClient.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/SocketClient.java
Sat Jul 10 16:05:48 2010
@@ -17,6 +17,7 @@
 
 package org.apache.commons.net;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -285,15 +286,31 @@ public abstract class SocketClient
      */
     public void disconnect() throws IOException
     {
-        if (_socket_ != null) _socket_.close();
-        if (_input_ != null) _input_.close();
-        if (_output_ != null) _output_.close();
-        if (_socket_ != null) _socket_ = null;
+        closeQuietly(_socket_);
+        closeQuietly(_input_);
+        closeQuietly(_output_);
+        _socket_ = null;
         _input_ = null;
         _output_ = null;
     }
 
-
+    private void closeQuietly(Socket socket) {
+        if (socket != null){
+            try {
+                socket.close();
+            } catch (IOException e) {
+            }
+        }
+    }
+
+    private void closeQuietly(Closeable close){
+        if (close != null){
+            try {
+                close.close();
+            } catch (IOException e) {
+            }
+        }
+    }
     /**
      * Returns true if the client is currently connected to a server.
      * <p>



Mime
View raw message