List of utility methods to do Socket Address Get
String | parseSocketAddressAddr(SocketAddress socketAddress) parse Socket Address Addr if (socketAddress != null) { final String addr = socketAddress.toString(); if (addr.length() > 0) { return addr.substring(1); return ""; |
int | sizeOfInet(InetSocketAddress inet) size Of Inet byte[] address = inet.getAddress().getAddress(); return 1 + address.length + 4; |
String | socketAddress2String(final SocketAddress addr) socket Address String StringBuilder sb = new StringBuilder(); InetSocketAddress inetSocketAddress = (InetSocketAddress) addr; sb.append(inetSocketAddress.getAddress().getHostAddress()); sb.append(":"); sb.append(inetSocketAddress.getPort()); return sb.toString(); |
SocketAddress | string2SocketAddress(final String addr) IP:PORT String[] s = addr.split(":"); return new InetSocketAddress(s[0], Integer.valueOf(s[1])); |
SocketAddress | stringAddressToSocketAddress(String address) string Address To Socket Address Objects.requireNonNull(address); String[] strings = address.split(":"); return new InetSocketAddress(strings[0], Integer.valueOf(strings[1])); |
String | stringifyInetSocketAddressList(InetSocketAddress[] addresses) stringify Inet Socket Address List StringBuilder sb = new StringBuilder(); for (int i = 0; i < addresses.length; i++) { sb.append(addresses[i].getAddress()).append(":").append(addresses[i].getPort()); if (i + 1 < addresses.length) { sb.append(", "); return sb.toString(); ... |
InetSocketAddress | stringToInetSocketAddress(String address, int defaultPort) Converts a address in format "hostname:port" to a InetSocketAddress InetSocketAddress isa; int pos = 0; if ((pos = address.indexOf(':')) == -1) { isa = new InetSocketAddress(address, defaultPort); } else { isa = new InetSocketAddress(address.substring(0, pos), Integer.parseInt(address.substring(pos + 1))); return isa; ... |
String | toAddressString(InetSocketAddress address) to Address String return address.getAddress().getHostAddress() + ":" + address.getPort(); |
byte[] | toByte(InetSocketAddress socketAddress) to Byte if (socketAddress == null) { throw new IllegalArgumentException("socketAddress is null"); InetAddress inetAddress = socketAddress.getAddress(); if (inetAddress == null) { throw new IllegalArgumentException("socketAddress is invalid"); byte[] address = inetAddress.getAddress(); ... |
byte[] | toBytes(SocketAddress address) Returns the given SocketAddress as a byte[] . return toBytes(getAddress(address), getPort(address));
|