List of utility methods to do HTTP Port Find
int | getRandomPort() get Random Port try (ServerSocket s = new ServerSocket(0)) { return s.getLocalPort(); } catch (IOException e) { throw new RuntimeException("Can't get random port"); |
List | getRandomPorts(int n) Create a list of currently available port numbers as strings. List<String> ports = new ArrayList<>(); for (int i = 0; i < n; i++) { ports.add(String.valueOf(getRandomPort())); return ports; |
String | getResponse(String name, String host, int port) get Response URL url = new URL("http://" + host + ":" + port + "/" + name); HttpURLConnection connection = connect(url); return toString(new BufferedInputStream(connection.getInputStream())); |
int | getServerPort() Get a server socket point for server, either TCP or UDP. int serverPort = 0; try { ServerSocket serverSocket = new ServerSocket(0); serverPort = serverSocket.getLocalPort(); serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Failed to get a server socket point"); return serverPort; |
String[] | getSupportedConnectionTypes(Map map) get Supported Connection Types String[] types = null; Object[] typeObjs = (Object[]) map.get("supportedConnectionTypes"); if (typeObjs != null) { types = new String[typeObjs.length]; for (int i = 0; i < typeObjs.length; i++) { types[i] = (String) typeObjs[i]; return types; |
Set | getSupportedEntityTypes() Returns a Set of supported entity types return supportedEntities;
|
int | getUnusedPort() Get a port that isn't currently used. ServerSocket s = new ServerSocket(0); int port = s.getLocalPort(); s.close(); return port; |
int | getUnusedPort(final int start) get Unused Port return getUnusedPort(start, DEFAULT_PORT_RANGE_END);
|
int | getUnusedPort(int startPort) Returns an unused port number on the local host. final int nTry = 20; for (int iPort = startPort; iPort < startPort + nTry; iPort++) { try { Socket trySocket = new Socket("localhost", iPort); if (!trySocket.isClosed()) { if (WARN_ABOUT_NOSUCHELEMENTEXCEPTIONS) { WARN_ABOUT_NOSUCHELEMENTEXCEPTIONS = false; System.err.println( ... |
int[] | getUnusedPorts(final int count, final int start) get Unused Ports return getUnusedPorts(count, start, DEFAULT_PORT_RANGE_END);
|