Pārlūkot izejas kodu

Add support for closing Sockets (could be removed if we switched to Java7)

Change-Id: I34aa3a772f7f777aa31ca6a243ad51bdc86fbb8e
Reviewed-on: http://gerrit.dmdirc.com/2462
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 12 gadus atpakaļ
vecāks
revīzija
093f9e66e9
1 mainītis faili ar 17 papildinājumiem un 0 dzēšanām
  1. 17
    0
      src/com/dmdirc/util/io/StreamUtils.java

+ 17
- 0
src/com/dmdirc/util/io/StreamUtils.java Parādīt failu

@@ -24,6 +24,7 @@ package com.dmdirc.util.io;
24 24
 
25 25
 import java.io.Closeable;
26 26
 import java.io.IOException;
27
+import java.net.Socket;
27 28
 
28 29
 /**
29 30
  * Utilities for dealing with streams.
@@ -53,4 +54,20 @@ public final class StreamUtils {
53 54
         }
54 55
     }
55 56
 
57
+    /**
58
+     * Closes the stream if it is non-null, and ignores any IOExceptions
59
+     * raised by doing so.
60
+     *
61
+     * @param stream The stream to be closed
62
+     */
63
+    public static void close(final Socket stream) {
64
+        if (stream != null) {
65
+            try {
66
+                stream.close();
67
+            } catch (IOException ex) {
68
+                // Do nothing. We don't care.
69
+            }
70
+        }
71
+    }
72
+
56 73
 }

Notiek ielāde…
Atcelt
Saglabāt