/** * Determines if a string contains a valid IP address. * @param s The string * @return Whether the string contains a valid IP address */ public static boolean isDottedQuad(String s) { byte [] address = Address.toByteArray(s, IPv4); return (address != null); }
/** * Determines if a string contains a valid IP address. * @param s The string * @return Whether the string contains a valid IP address */ public static boolean isDottedQuad(String s) { byte [] address = Address.toByteArray(s, IPv4); return (address != null); }
/** * Determines if a string contains a valid IP address. * @param s The string * @return Whether the string contains a valid IP address */ public static boolean isDottedQuad(String s) { byte [] address = Address.toByteArray(s, IPv4); return (address != null); }
/** * Determines if a string contains a valid IP address. * @param s The string * @return Whether the string contains a valid IP address */ public static boolean isDottedQuad(String s) { byte [] address = Address.toByteArray(s, IPv4); return (address != null); }
/** * Convert a string containing an IP address to an array of 4 or 16 integers. * @param s The address, in text format. * @param family The address family. * @return The address */ public static int [] toArray(String s, int family) { byte [] byteArray = toByteArray(s, family); if (byteArray == null) return null; int [] intArray = new int[byteArray.length]; for (int i = 0; i < byteArray.length; i++) intArray[i] = byteArray[i] & 0xFF; return intArray; }
/** * Convert a string containing an IP address to an array of 4 or 16 integers. * @param s The address, in text format. * @param family The address family. * @return The address */ public static int [] toArray(String s, int family) { byte [] byteArray = toByteArray(s, family); if (byteArray == null) return null; int [] intArray = new int[byteArray.length]; for (int i = 0; i < byteArray.length; i++) intArray[i] = byteArray[i] & 0xFF; return intArray; }
/** * Convert a string containing an IP address to an array of 4 or 16 integers. * @param s The address, in text format. * @param family The address family. * @return The address */ public static int [] toArray(String s, int family) { byte [] byteArray = toByteArray(s, family); if (byteArray == null) return null; int [] intArray = new int[byteArray.length]; for (int i = 0; i < byteArray.length; i++) intArray[i] = byteArray[i] & 0xFF; return intArray; }
/** * Convert a string containing an IP address to an array of 4 or 16 integers. * @param s The address, in text format. * @param family The address family. * @return The address */ public static int [] toArray(String s, int family) { byte [] byteArray = toByteArray(s, family); if (byteArray == null) return null; int [] intArray = new int[byteArray.length]; for (int i = 0; i < byteArray.length; i++) intArray[i] = byteArray[i] & 0xFF; return intArray; }
@Nonnull public static byte[] toAddress(@Nonnull String ipAsString) { byte[] address = toByteArray(ipAsString, IPv4); if (address == null) { address = toByteArray(ipAsString, IPv6); } if (address == null) { throw new IllegalArgumentException(ipAsString + " is no valid ip in string format."); } return address; }
/** * Converts an address from its string representation to an IP address. * The address can be either IPv4 or IPv6. * @param addr The address, in string form * @return The IP addresses * @exception UnknownHostException The address is not a valid IP address. */ public static InetAddress getByAddress(String addr) throws UnknownHostException { byte [] bytes; bytes = toByteArray(addr, IPv4); if (bytes != null) return InetAddress.getByAddress(bytes); bytes = toByteArray(addr, IPv6); if (bytes != null) return InetAddress.getByAddress(bytes); throw new UnknownHostException("Invalid address: " + addr); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr) throws UnknownHostException { byte [] array = Address.toByteArray(addr, Address.IPv4); if (array == null) array = Address.toByteArray(addr, Address.IPv6); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr) throws UnknownHostException { byte [] array = Address.toByteArray(addr, Address.IPv4); if (array == null) array = Address.toByteArray(addr, Address.IPv6); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
/** * Converts an address from its string representation to an IP address in * a particular family. * @param addr The address, in string form * @param family The address family, either IPv4 or IPv6. * @return The IP addresses * @exception UnknownHostException The address is not a valid IP address in * the specified address family. */ public static InetAddress getByAddress(String addr, int family) throws UnknownHostException { if (family != IPv4 && family != IPv6) throw new IllegalArgumentException("unknown address family"); byte [] bytes; bytes = toByteArray(addr, family); if (bytes != null) return InetAddress.getByAddress(addr, bytes); throw new UnknownHostException("Invalid address: " + addr); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr) throws UnknownHostException { byte [] array = Address.toByteArray(addr, Address.IPv4); if (array == null) array = Address.toByteArray(addr, Address.IPv6); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr, int family) throws UnknownHostException { byte [] array = Address.toByteArray(addr, family); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr, int family) throws UnknownHostException { byte [] array = Address.toByteArray(addr, family); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
@Nonnull public static ARecord a(@Nonnull String name, @Nonnegative long ttl, @Nonnull String ipv4) { return a(name, ttl, toByteArray(ipv4, IPv4)); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr, int family) throws UnknownHostException { byte [] array = Address.toByteArray(addr, family); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
/** * Creates a reverse map name corresponding to an address contained in * a String. * @param addr The address from which to build a name. * @return The name corresponding to the address in the reverse map. * @throws UnknownHostException The string does not contain a valid address. */ public static Name fromAddress(String addr, int family) throws UnknownHostException { byte [] array = Address.toByteArray(addr, family); if (array == null) throw new UnknownHostException("Invalid IP address"); return fromAddress(array); }
/** * Gets the next token from a tokenizer and converts it to a byte array * containing an IP address. * @param family The address family. * @return The next token in the stream, as an byte array representing an IP * address. * @throws TextParseException The input was invalid or not a valid address. * @throws IOException An I/O error occurred. * @see Address */ public byte [] getAddressBytes(int family) throws IOException { String next = _getIdentifier("an address"); byte [] bytes = Address.toByteArray(next, family); if (bytes == null) throw exception("Invalid address: " + next); return bytes; }