/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }
/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }
/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }
/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Returns the {@link Inet6Address} representation of a {@link CharSequence} IP address. * <p> * The {@code ipv4Mapped} parameter specifies how IPv4 addresses should be treated. * "IPv4 mapped" format as * defined in <a href="http://tools.ietf.org/html/rfc4291#section-2.5.5">rfc 4291 section 2</a> is supported. * @param ip {@link CharSequence} IP address to be converted to a {@link Inet6Address} * @param ipv4Mapped * <ul> * <li>{@code true} To allow IPv4 mapped inputs to be translated into {@link Inet6Address}</li> * <li>{@code false} Consider IPv4 mapped addresses as invalid.</li> * </ul> * @return {@link Inet6Address} representation of the {@code ip} or {@code null} if not a valid IP address. */ public static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped) { byte[] bytes = getIPv6ByName(ip, ipv4Mapped); if (bytes == null) { return null; } try { return Inet6Address.getByAddress(null, bytes, -1); } catch (UnknownHostException e) { throw new RuntimeException(e); // Should never happen } }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }
/** * Creates an byte[] based on an ipAddressString. No error handling is performed here. */ public static byte[] createByteArrayFromIpAddressString(String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { return validIpV4ToBytes(ipAddressString); } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1); } int percentPos = ipAddressString.indexOf('%'); if (percentPos >= 0) { ipAddressString = ipAddressString.substring(0, percentPos); } return getIPv6ByName(ipAddressString, true); } return null; }