You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2017/07/20 05:30:34 UTC
svn commit: r1802447 -
/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/FreeSocketPortUtil.java
Author: ggregory
Date: Thu Jul 20 05:30:34 2017
New Revision: 1802447
URL: http://svn.apache.org/viewvc?rev=1802447&view=rev
Log:
Use try-with-resources.
Modified:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/FreeSocketPortUtil.java
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/FreeSocketPortUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/FreeSocketPortUtil.java?rev=1802447&r1=1802446&r2=1802447&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/FreeSocketPortUtil.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/FreeSocketPortUtil.java Thu Jul 20 05:30:34 2017
@@ -20,11 +20,9 @@ package org.apache.commons.vfs2.util;
import java.io.IOException;
import java.net.ServerSocket;
-public class FreeSocketPortUtil
-{
+public class FreeSocketPortUtil {
- public static void main(final String[] args) throws IOException
- {
+ public static void main(final String[] args) throws IOException {
System.out.println(FreeSocketPortUtil.findFreeLocalPort());
}
@@ -34,15 +32,9 @@ public class FreeSocketPortUtil
* @return a free local socket port.
* @throws IOException
*/
- public static int findFreeLocalPort() throws IOException
- {
- final ServerSocket server = new ServerSocket(0);
- try
- {
+ public static int findFreeLocalPort() throws IOException {
+ try (final ServerSocket server = new ServerSocket(0)) {
return server.getLocalPort();
- } finally
- {
- server.close();
}
}
}