/** * Converts a byte array into an IPv6 address. * * @param value the IPv6 address value stored in network byte order * (i.e., the most significant byte first) * @return an IPv6 address * @throws IllegalArgumentException if the argument is invalid */ public static Ip6Address valueOf(byte[] value) { return new Ip6Address(value); }
/** * Converts an InetAddress into an IPv6 address. * * @param inetAddress the InetAddress value to use. It must contain an IPv6 * address * @return an IPv6 address * @throws IllegalArgumentException if the argument is invalid */ public static Ip6Address valueOf(InetAddress inetAddress) { byte[] bytes = inetAddress.getAddress(); if (inetAddress instanceof Inet6Address) { return new Ip6Address(bytes); } if ((inetAddress instanceof Inet4Address) || (bytes.length == INET_BYTE_LENGTH)) { final String msg = "Invalid IPv6 version address string: " + inetAddress.toString(); throw new IllegalArgumentException(msg); } // Use the number of bytes as a hint if (bytes.length == INET6_BYTE_LENGTH) { return new Ip6Address(bytes); } final String msg = "Unrecognized IP version address string: " + inetAddress.toString(); throw new IllegalArgumentException(msg); }
/** * Creates an IPv6 network mask prefix. * * @param prefixLength the length of the mask prefix. Must be in the * interval [0, 128] * @return a new IPv6 address that contains a mask prefix of the * specified length * @throws IllegalArgumentException if the arguments are invalid */ public static Ip6Address makeMaskPrefix(int prefixLength) { byte[] mask = IpAddress.makeMaskPrefixArray(VERSION, prefixLength); return new Ip6Address(mask); }