List of utility methods to do Socket Address Get
String | getPort(InetSocketAddress socket) get Port return socket.getPort() + ""; |
Integer | getPort(SocketAddress socketAddress) get Port if (socketAddress == null) { return 0; String address = socketAddress.toString(); return Integer.valueOf(address.substring(address.indexOf(':') + 1)); |
InetSocketAddress | getRandomLoopbackInetSocketAddress(final int port) get Random Loopback Inet Socket Address return new InetSocketAddress(getRandomLoopbackIpAddress(), port); |
String | getRawAddress(InetSocketAddress inetSocketAddress) get Raw Address InetAddress address = inetSocketAddress.getAddress();
return address != null ? address.getHostAddress() : inetSocketAddress.getHostName();
|
String | getSimpleIpport(SocketAddress remoteAddr) get Simple Ipport if (remoteAddr == null) { return null; if (remoteAddr instanceof InetSocketAddress) { InetSocketAddress addr = (InetSocketAddress) remoteAddr; return String.format("%s:%d", addr.getHostString(), addr.getPort()); return remoteAddr.toString(); ... |
String | getSocketAddress(InetSocketAddress socket) get Socket Address return getHostName(socket) + ":" + getPort(socket); |
String | getSocketAddress(SocketAddress socketAddress) get Socket Address String address = socketAddress.toString(); int addressLength = address.length(); if (addressLength > 0) { if (address.startsWith("/")) { return address.substring(1); } else { final int delimeterIndex = address.indexOf('/'); if (delimeterIndex != -1 && delimeterIndex < addressLength) { ... |
SocketAddress | getSocketAddress(String hostHeader) Get socket address from Host header. int pivot = hostHeader.indexOf(':'); if (pivot == -1) { return new InetSocketAddress(hostHeader, 80); return new InetSocketAddress(hostHeader.substring(0, pivot), Integer.parseInt(hostHeader.substring(pivot + 1, hostHeader.length()))); |
InetSocketAddress[] | getSocketAddressList(String list, int defaultPort) Parse space delimited addresss[:port] string and return array of InetSocketAddress .
return getSocketAddressList(list, defaultPort, null);
|
String | getSocketConnectString(InetSocketAddress socketAddress) get Socket Connect String String host; InetAddress address = socketAddress.getAddress(); if (address == null) { host = socketAddress.getHostString(); } else if (address.isAnyLocalAddress() || address.isLoopbackAddress()) { host = address.getCanonicalHostName(); } else { host = address.getHostName(); ... |