/** * Constructor for given IP address version and address octets. * * @param version the IP address version * @param value the IP address value stored in network byte order * (i.e., the most significant byte first) * @throws IllegalArgumentException if the arguments are invalid */ protected IpAddress(Version version, byte[] value) { checkArguments(version, value, 0); this.version = version; switch (version) { case INET: this.octets = Arrays.copyOf(value, INET_BYTE_LENGTH); break; case INET6: this.octets = Arrays.copyOf(value, INET6_BYTE_LENGTH); break; default: // Should not be reached this.octets = null; break; } }
/** * Converts a byte array and a given offset from the beginning of the * array into an IPv6 address. * <p> * The IP address is stored in network byte order (i.e., the most * significant byte first). * </p> * @param value the value to use * @param offset the offset in bytes from the beginning of the byte array * @return an IPv6 address * @throws IllegalArgumentException if the arguments are invalid */ public static Ip6Address valueOf(byte[] value, int offset) { IpAddress.checkArguments(VERSION, value, offset); byte[] bc = Arrays.copyOfRange(value, offset, value.length); return Ip6Address.valueOf(bc); }
/** * Converts a byte array and a given offset from the beginning of the * array into an IPv4 address. * <p> * The IP address is stored in network byte order (i.e., the most * significant byte first). * </p> * @param value the value to use * @param offset the offset in bytes from the beginning of the byte array * @return an IPv4 address * @throws IllegalArgumentException if the arguments are invalid */ public static Ip4Address valueOf(byte[] value, int offset) { IpAddress.checkArguments(VERSION, value, offset); byte[] bc = Arrays.copyOfRange(value, offset, value.length); return Ip4Address.valueOf(bc); }
/** * Converts a byte array and a given offset from the beginning of the * array into an IP address. * <p> * The IP address is stored in network byte order (i.e., the most * significant byte first). * </p> * @param version the IP address version * @param value the value to use * @param offset the offset in bytes from the beginning of the byte array * @return an IP address * @throws IllegalArgumentException if the arguments are invalid */ public static IpAddress valueOf(Version version, byte[] value, int offset) { checkArguments(version, value, offset); byte[] bc = Arrays.copyOfRange(value, offset, value.length); return IpAddress.valueOf(version, bc); }