List of utility methods to do InetAddress
boolean | inetAddressGt(InetAddress a, InetAddress b) inet Address Gt return !inetAddressLeq(a, b);
|
byte[] | inetAddrToByteArray(InetAddress a) inet Addr To Byte Array return a.getAddress();
|
InterfaceAddress | newInterfaceAddress(InetAddress inetAddress, short maskLength) new Interface Address try { final Constructor<InterfaceAddress> ctor = InterfaceAddress.class.getDeclaredConstructor(); ctor.setAccessible(true); final Field addressField = InterfaceAddress.class.getDeclaredField("address"); addressField.setAccessible(true); final Field maskLengthField = InterfaceAddress.class.getDeclaredField("maskLength"); maskLengthField.setAccessible(true); final InterfaceAddress interfaceAddress = ctor.newInstance(); ... |
String | normalizeHostAddress(final InetAddress localHost) normalize Host Address if (localHost instanceof Inet6Address) { return "[" + localHost.getHostAddress() + "]"; } else { return localHost.getHostAddress(); |
InetAddress | parseInetAddressFromString(String input) parse Inet Address From String try { InetAddress address = InetAddress.getByName(input); return address; } catch (Exception ex) { return null; |
InetAddress | readInetAddress(final DataInput in, final boolean fixedLength) read Inet Address if (in.readBoolean()) { if (fixedLength) { in.readByte(); in.readLong(); in.readLong(); return null; final byte addrLength = in.readByte(); switch (addrLength) { case 4: final int address = in.readInt(); if (fixedLength) { in.readInt(); in.readLong(); final byte[] addr = new byte[4]; addr[0] = (byte) (address >>> 24 & 0xFF); addr[1] = (byte) (address >>> 16 & 0xFF); addr[2] = (byte) (address >>> 8 & 0xFF); addr[3] = (byte) (address & 0xFF); return InetAddress.getByAddress(addr); case 16: final byte[] result = new byte[16]; in.readFully(result); return InetAddress.getByAddress(result); default: throw new IOException("Unknown address format, length: " + addrLength); |
InetAddress | readInetAddress(final String stringInetAddress) read Inet Address try { return InetAddress.getByName(stringInetAddress); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); |
InetAddress[] | remove(InetAddress[] a_, InetAddress b) remove InetAddress[] a = (InetAddress[]) a_.clone(); for (int i = 0; i < a.length; i++) if (b.equals(a[i])) { a[i] = null; break; return removeNull(a); |
InetAddress[] | removeNull(InetAddress addrs[]) remove Null int count = 0; for (int i = 0; i < addrs.length; i++) if (addrs[i] != null) count++; InetAddress[] result = new InetAddress[count]; count = 0; for (int i = 0; i < addrs.length; i++) if (addrs[i] != null) ... |
void | serialize(InetAddress endpoint, DataOutput out) serialize byte[] buf = endpoint.getAddress();
out.writeByte(buf.length);
out.write(buf);
|