File tree Expand file tree Collapse file tree
src/java/org/apache/commons/io Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3131import java .io .PrintWriter ;
3232import java .io .Reader ;
3333import java .io .Writer ;
34+ import java .net .Socket ;
3435import java .nio .channels .Channel ;
3536import java .util .ArrayList ;
3637import java .util .Collection ;
@@ -221,6 +222,24 @@ public static void closeQuietly(Closeable closeable) {
221222 }
222223 }
223224
225+ /**
226+ * Unconditionally close a <code>Socket</code>.
227+ * <p>
228+ * Equivalent to {@link Socket#close()}, except any exceptions will be ignored.
229+ * This is typically used in finally blocks.
230+ *
231+ * @param sock the Socket to close, may be null or already closed
232+ */
233+ public static void closeQuietly (Socket sock ){
234+ if (sock != null ){
235+ try {
236+ sock .close ();
237+ } catch (IOException ioe ) {
238+ // ignored
239+ }
240+ }
241+ }
242+
224243 /**
225244 * Fetches entire contents of an <code>InputStream</code> and represent
226245 * same data as result InputStream.
You can’t perform that action at this time.
0 commit comments