List of utility methods to do Socket Address Get
InetSocketAddress | normalizeSocketAddr(InetSocketAddress address) normalize Socket Addr return new InetSocketAddress(extractHostAddr(address), address.getPort()); |
String[] | parseAddress(SocketAddress address) parse Address String addressStr = address.toString(); if (addressStr.startsWith("/")) { addressStr = addressStr.replace("/", ""); String[] tmp = addressStr.split(":"); return tmp; |
InetSocketAddress | parseInetSocketAddress(String address) Parses InetSocketAddress from a String. if (address == null) { return null; String[] strArr = address.split(":"); if (strArr.length != 2) { throw new IOException("Invalid InetSocketAddress " + address); return new InetSocketAddress(strArr[0], Integer.parseInt(strArr[1])); ... |
InetSocketAddress | parseInetSocketAddress(String endPoint) Parse an InetSocketAddress object the given string. String hostname = null; String portString; int port; int index = endPoint.indexOf(":"); if (index >= 0) { hostname = endPoint.substring(0, index); portString = endPoint.substring(index + 1); } else { ... |
InetSocketAddress | parseInetSocketAddress(String text) parse Inet Socket Address if (text == null || text.isEmpty()) { throw new IllegalArgumentException("Address is empty"); final int index = text.lastIndexOf(':'); if (index == -1 || index == text.length() - 1) { throw new IllegalArgumentException("Port is not found in: " + text); if (index == 0) { ... |
InetSocketAddress | parseSocketAddress(String address) parse Socket Address String[] tokens = address.split(":"); if (tokens.length != 2) return null; return parseSocketAddress(tokens[0], tokens[1]); |
InetSocketAddress | parseSocketAddress(String addressPort, int defaultPort) parse Socket Address String address = addressPort; int port = defaultPort; int lastColon = (addressPort != null) ? addressPort.lastIndexOf(":") : -1; if (lastColon >= 0) { if (addressPort.indexOf(":") == lastColon) { address = addressPort.substring(0, lastColon); port = Integer.parseInt(addressPort.substring(lastColon + 1)); } else { ... |
InetSocketAddress | parseSocketAddress(String addrString) Parses the string and returns a InetSocketAddress. return parseSocketAddress(addrString, -1);
|
InetSocketAddress | parseSocketAddress(String anAddress) Parses a String containing a SokectAddress formatted as either: <host> ":" <port> "[" <numeric_host> "]:" <port> String hostAddress; String port; if (anAddress.startsWith("[")) { int endBracketAt = anAddress.indexOf(']'); int portSeparatorAt = anAddress.lastIndexOf(':'); if (-1 == endBracketAt) { throw new IllegalArgumentException("missing final ]"); if (-1 == portSeparatorAt) { throw new IllegalArgumentException("missing port separator"); if (portSeparatorAt < endBracketAt) { throw new IllegalArgumentException("missing port"); hostAddress = anAddress.substring(1, endBracketAt); port = anAddress.substring(portSeparatorAt); } else { int portSeparatorAt = anAddress.lastIndexOf(':'); if (-1 == portSeparatorAt) { throw new IllegalArgumentException("missing port separator"); hostAddress = anAddress.substring(0, portSeparatorAt); port = anAddress.substring(portSeparatorAt + 1); int portNum = Integer.parseInt(port); return InetSocketAddress.createUnresolved(hostAddress, portNum); |
InetSocketAddress | parseSocketAddress(String socketAddress) parse Socket Address if (socketAddress != null) { int colonIdx = socketAddress.indexOf(':'); if (colonIdx != -1) { String hostName = socketAddress.substring(0, colonIdx); String port = socketAddress.substring(colonIdx + 1); return new InetSocketAddress(hostName, Integer.parseInt(port)); return null; |