public class IPv4Address extends IPAddress implements Iterable<IPv4Address>
You can construct an IPv4 address from a byte array, from an int, from a Address.SegmentValueProvider,
from Inet4Address, from an IPv4AddressSection of 4 segments, or from an array of 4 IPv4AddressSegment objects.
To construct one from a String use
IPAddressString.toAddress() or IPAddressString.getAddress(), IPAddressString.toHostAddress() or IPAddressString.getHostAddress()
| Modifier and Type | Class and Description |
|---|---|
static class |
IPv4Address.inet_aton_radix |
static interface |
IPv4Address.IPv4AddressConverter |
IPAddress.DualIPv4Pv6Arrays, IPAddress.IPAddressValueProvider, IPAddress.IPVersionAddress.AddressValueProvider, Address.SegmentValueProvider| Modifier and Type | Field and Description |
|---|---|
static int |
BIT_COUNT |
static int |
BITS_PER_SEGMENT |
static int |
BYTE_COUNT |
static int |
BYTES_PER_SEGMENT |
static int |
DEFAULT_TEXTUAL_RADIX |
static int |
MAX_VALUE |
static int |
MAX_VALUE_PER_SEGMENT |
static String |
REVERSE_DNS_SUFFIX |
static int |
SEGMENT_COUNT |
static char |
SEGMENT_SEPARATOR |
BINARY_STR_PREFIX, DEFAULT_ADDRESS_CONVERTER, PREFIX_LEN_SEPARATORADDRESS_HIGH_VALUE_COMPARATOR, ADDRESS_LOW_VALUE_COMPARATOR, ALTERNATIVE_RANGE_SEPARATOR, ALTERNATIVE_RANGE_SEPARATOR_STR, ALTERNATIVE_SEGMENT_WILDCARD_STR, DEFAULT_ADDRESS_COMPARATOR, HEX_PREFIX, OCTAL_PREFIX, RANGE_SEPARATOR, RANGE_SEPARATOR_STR, SEGMENT_SQL_SINGLE_WILDCARD, SEGMENT_SQL_SINGLE_WILDCARD_STR, SEGMENT_SQL_WILDCARD, SEGMENT_SQL_WILDCARD_STR, SEGMENT_WILDCARD, SEGMENT_WILDCARD_STR| Constructor and Description |
|---|
IPv4Address(Address.SegmentValueProvider valueProvider)
Constructs an IPv4 address.
|
IPv4Address(Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider)
Constructs an IPv4 address or subnet.
|
IPv4Address(Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider,
Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
IPv4Address(Address.SegmentValueProvider valueProvider,
Integer networkPrefixLength)
Constructs an IPv4 address.
|
IPv4Address(byte[] bytes)
Constructs an IPv4 address.
|
IPv4Address(byte[] bytes,
Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
IPv4Address(byte[] bytes,
int byteStartIndex,
int byteEndIndex)
Constructs an IPv4 address or subnet.
|
IPv4Address(byte[] bytes,
int byteStartIndex,
int byteEndIndex,
Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
IPv4Address(Inet4Address inet4Address)
Constructs an IPv4 address.
|
IPv4Address(Inet4Address inet4Address,
Integer networkPrefixLength)
Constructs an IPv4 address.
|
IPv4Address(int address)
Constructs an IPv4 address.
|
IPv4Address(int address,
Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
IPv4Address(IPv4AddressSection section)
Constructs an IPv4 address or subnet.
|
IPv4Address(IPv4AddressSegment[] segments)
Constructs an IPv4 address or subnet.
|
IPv4Address(IPv4AddressSegment[] segments,
Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
| Modifier and Type | Method and Description |
|---|---|
IPv4Address |
adjustPrefixBySegment(boolean nextSegment)
Increases or decreases prefix length to the next segment boundary.
|
IPv4Address |
adjustPrefixBySegment(boolean nextSegment,
boolean zeroed)
Increases or decreases prefix length to the next segment boundary.
|
IPv4Address |
adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.
|
IPv4Address |
adjustPrefixLength(int adjustment,
boolean zeroed)
Increases or decreases prefix length by the given increment.
|
IPv4Address |
applyPrefixLength(int networkPrefixLength)
Deprecated.
|
IPv4Address |
assignMinPrefixForBlock()
Constructs an equivalent address with the smallest CIDR prefix possible (largest network),
such that the range of values are a set of subnet blocks for that prefix.
|
IPv4Address |
assignPrefixForSingleBlock()
Returns the equivalent CIDR address with a prefix length for which the address subnet block matches the range of values in this address.
|
IPv4Address |
bitwiseOr(IPAddress mask)
Equivalent to calling
IPAddress.bitwiseOr(IPAddress, boolean) with the second argument as false. |
IPv4Address |
bitwiseOr(IPAddress mask,
boolean retainPrefix)
Does the bitwise disjunction with this address.
|
IPv4Address |
bitwiseOrNetwork(IPAddress mask,
int networkPrefixLength)
Does the bitwise disjunction with this address.
|
Iterator<IPv4Address> |
blockIterator(int segmentCount)
Iterates through series that can be obtained by iterating through all the upper segments up to the given segment count.
|
AddressComponentSpliterator<IPv4Address> |
blockSpliterator(int segmentCount)
Partitions and traverses through the individual sequential blocks created from each of the individual values up to the given segment count.
|
Stream<IPv4Address> |
blockStream(int segmentCount)
Returns a sequential stream of the individual blocks created from each of the individual values up to the given segment count.
|
IPv4Address |
coverWithPrefixBlock()
Returns the minimal-size prefix block that covers all the values in this series.
|
IPv4Address |
coverWithPrefixBlock(IPAddress other)
Returns the minimal-size prefix block that covers all the addresses spanning from this subnet to the given subnet.
|
BigInteger |
enumerate(Address other)
Indicates where an address sits relative to the subnet ordering.
|
BigInteger |
enumerate(IPAddress other)
Indicates where an address sits relative to the subnet ordering.
|
Long |
enumerateIPv4(IPv4Address other)
Indicates where an address sits relative to the subnet ordering.
|
int |
getBitCount()
Provides the number of bits comprising this address item
|
int |
getByteCount()
Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8
|
IPv4AddressSegment |
getDivision(int index) |
IPv4Address |
getHostMask()
Returns the host mask associated with the CIDR network prefix length of this series.
|
IPv4AddressSection |
getHostSection()
Returns the host section of the series.
|
IPv4AddressSection |
getHostSection(int networkPrefixLength)
Returns the host section of the address as indicated by the network prefix length provided.
|
IPv6Address |
getIPv4MappedAddress() |
IPv6Address |
getIPv6Address(IPv6AddressSegment[] segs)
Create an IPv6 mixed address using the given ipv6 segments and using this address for the embedded IPv4 segments
|
IPv6AddressNetwork |
getIPv6Network()
Returns the IPv6 network used by
getIPv4MappedAddress() and getIPv6Address(IPv6AddressSegment[]) |
Iterable<IPv4Address> |
getIterable()
Useful for using an instance in a "for-each loop".
|
IPv4Address |
getLower()
If this represents a series with ranging values, returns a series representing the lower values of the range.
|
IPv4Address |
getLowerNonZeroHost()
Similar to
IPAddressSegmentSeries.getLower(), but will not return a series that has a prefix length and whose host value is zero. |
IPv4AddressNetwork |
getNetwork()
Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)
|
IPv4Address |
getNetworkMask()
Returns the network mask associated with the CIDR network prefix length of this series.
|
IPv4AddressSection |
getNetworkSection()
Returns the network section of the series if the series has a CIDR network prefix length,
otherwise it returns the entire series as a prefixed series with prefix matching the address bit length.
|
IPv4AddressSection |
getNetworkSection(int networkPrefixLength)
Returns the network section of the series.
|
IPv4AddressSection |
getNetworkSection(int networkPrefixLength,
boolean withPrefixLength)
Returns the network section of the series.
|
IPAddressStringDivisionSeries[] |
getParts(IPAddressSection.IPStringBuilderOptions options)
Returns all the ways of breaking this address down into segments, as selected.
|
IPAddressStringDivisionSeries[] |
getParts(IPv4AddressSection.IPv4StringBuilderOptions options) |
IPv4AddressSection |
getSection()
Returns the address as an address section comprising all segments in the address.
|
IPv4AddressSection |
getSection(int index)
Gets the subsection from the series starting from the given index
The first segment is at index 0.
|
IPv4AddressSection |
getSection(int index,
int endIndex)
Gets the subsection from the series starting from the given index and ending just before the give endIndex
The first segment is at index 0.
|
IPv4AddressSegment |
getSegment(int index)
Returns the segment from this series at the given index.
|
int |
getSegmentCount()
Returns the number of segments in this series.
|
IPv4AddressSegment[] |
getSegments()
Returns the segments of this series of segments as an array.
|
IPv4Address |
getUpper()
If this represents a series with ranging values, returns a series representing the upper values of the range.
|
IPv4Address |
increment(long increment)
Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0
returning the first address in the range.
|
IPv4Address |
incrementBoundary(long increment)
If the given increment is positive, adds the value to the upper series (
AddressSegmentSeries.getUpper()) in the subnet range to produce a new series. |
IPv4Address |
intersect(IPAddress other)
Produces the subnet whose addresses are found in both this and the given subnet argument, or null if no such addresses.
|
int |
intValue()
Returns the address (or lowest value of the address if a subnet) as a signed integer
|
boolean |
isIPv4() |
boolean |
isIPv4Convertible()
Determines whether this address can be converted to IPv4, if not IPv4 already.
|
boolean |
isIPv6Convertible()
Override this method to convert in your own way.
|
boolean |
isLinkLocal()
Returns whether the address is link local, whether unicast or multicast.
|
boolean |
isLocal()
Returns true if the address is link local, site local, organization local, administered locally, or unspecified.
|
boolean |
isLoopback() |
boolean |
isMulticast()
Whether the MAC address or IP address or other form of address is multicast.
|
boolean |
isPrivate()
Unicast addresses allocated for private use
|
Iterator<IPv4Address> |
iterator()
Iterates through the individual address components.
|
long |
longValue()
Returns the address (or lowest value of the address if a subnet) as a positive integer
|
IPv4Address |
mask(IPAddress mask)
Equivalent to calling
IPAddress.mask(IPAddress, boolean) with the second argument as false. |
IPv4Address |
mask(IPAddress mask,
boolean retainPrefix)
Applies the given mask to all addresses represented by this IPAddress.
|
IPv4Address |
maskNetwork(IPAddress mask,
int networkPrefixLength)
Applies the given mask to all addresses represented by this IPAddress while also applying the given prefix length at the same time.
|
IPv4Address[] |
mergeToPrefixBlocks(IPAddress... addresses)
Merges this with the list of addresses to produce the smallest list of prefix blocks.
|
IPv4Address[] |
mergeToSequentialBlocks(IPAddress... addresses)
Merges this with the list of subnets to produce the smallest list of block subnets that are sequential.
|
Iterator<IPv4Address> |
nonZeroHostIterator()
Similar to the iterator, but series with a host of zero are skipped.
|
Iterator<IPv4Address> |
prefixBlockIterator()
Iterates through the individual prefix blocks.
|
Iterator<IPv4Address> |
prefixBlockIterator(int prefixLength)
Iterates through the range of prefix blocks in this range instance using the given prefix length.
|
AddressComponentSpliterator<IPv4Address> |
prefixBlockSpliterator()
Partitions and traverses through the individual prefix blocks for the prefix length of this series.
|
AddressComponentSpliterator<IPv4Address> |
prefixBlockSpliterator(int prefixLength)
Partitions and traverses through the individual prefix blocks for the given prefix length.
|
Stream<IPv4Address> |
prefixBlockStream()
Returns a sequential stream of the individual prefix blocks for the prefix length of this series.
|
Stream<IPv4Address> |
prefixBlockStream(int prefixLength)
Returns a sequential stream of the prefix blocks for the given prefix length.
|
Iterator<IPv4Address> |
prefixIterator()
Iterates through the individual prefixes.
|
Iterator<IPv4Address> |
prefixIterator(int prefixLength)
Iterates through the range of prefixes in this range instance using the given prefix length.
|
AddressComponentSpliterator<IPv4Address> |
prefixSpliterator()
Partitions and traverses through the individual prefixes for the prefix length of this series.
|
AddressComponentSpliterator<IPv4Address> |
prefixSpliterator(int prefixLength)
Partitions and traverses through the individual prefixes for the given prefix length.
|
Stream<IPv4Address> |
prefixStream()
Returns a sequential stream of the individual prefixes for the prefix length of this series.
|
Stream<IPv4Address> |
prefixStream(int prefixLength)
Returns a sequential stream of the individual prefixes for the given prefix length.
|
IPv4Address |
removePrefixLength()
Deprecated.
|
IPv4Address |
removePrefixLength(boolean zeroed)
Deprecated.
|
IPv4Address |
replace(int startIndex,
int endIndex,
IPv4Address replacement,
int replacementIndex)
Replaces segments starting from startIndex and ending before endIndex with the same number of segments starting at replacementStartIndex from the replacement section
|
IPv4Address |
replace(int startIndex,
IPv4AddressSection replacement)
Replaces segments starting from startIndex with as many segments as possible from the replacement section
|
IPv4Address |
reverseBits(boolean perByte)
Returns a new segment series with the bits reversed.
|
IPv4Address |
reverseBytes()
Returns a new segment series with the bytes reversed.
|
IPv4Address |
reverseBytesPerSegment()
Returns a new segment series with the bytes reversed within each segment.
|
IPv4Address |
reverseSegments()
Returns a new segment series with the segments reversed.
|
Iterator<IPv4AddressSegment[]> |
segmentsIterator()
Iterates through the individual segments.
|
Iterator<IPv4AddressSegment[]> |
segmentsNonZeroHostIterator()
Similar to the segments iterator, but series with a host of zero are skipped.
|
AddressComponentRangeSpliterator<IPv4Address,IPv4AddressSegment[]> |
segmentsSpliterator()
Partitions and traverses through the individual segment arrays.
|
Stream<IPv4AddressSegment[]> |
segmentsStream()
Returns a sequential stream of the individual segment arrays.
|
Iterator<IPv4Address> |
sequentialBlockIterator()
Iterates through the sequential series that make up this series.
|
AddressComponentSpliterator<IPv4Address> |
sequentialBlockSpliterator()
Partitions and traverses through the individual sequential blocks.
|
Stream<IPv4Address> |
sequentialBlockStream()
Returns a sequential stream of the individual sequential blocks.
|
IPv4Address |
setPrefixLength(int prefixLength)
Sets the prefix length.
|
IPv4Address |
setPrefixLength(int prefixLength,
boolean zeroed)
Sets the prefix length.
|
IPv4Address |
setPrefixLength(int prefixLength,
boolean zeroed,
boolean zeroHostIsBlock)
Sets the prefix length while allowing the caller to control whether bits moved in or out of the prefix become zero,
and whether a zero host for the new prefix bits can be translated into a prefix block.
|
IPv4Address[] |
spanWithPrefixBlocks()
Produces an array of prefix blocks that cover the same set of addresses as this.
|
IPv4Address[] |
spanWithPrefixBlocks(IPAddress other)
Produces the list of prefix block subnets that span from this subnet to the given subnet.
|
IPv4AddressSeqRange |
spanWithRange(IPAddress other)
Produces an IPAddressRange instance that spans this subnet to the given subnet.
|
IPv4Address[] |
spanWithSequentialBlocks()
Produces an array of blocks that are sequential that cover the same set of addresses as this.
|
IPv4Address[] |
spanWithSequentialBlocks(IPAddress other)
Produces a list of sequential block subnets that span all values from this subnet to the given subnet.
|
AddressComponentSpliterator<IPv4Address> |
spliterator()
Partitions and traverses through the individual address components.
|
Stream<IPv4Address> |
stream()
Returns a sequential stream of the individual address components.
|
IPv4Address[] |
subtract(IPAddress other)
Subtract the given subnet from this subnet, returning an array of subnets for the result (the subnets will not be contiguous so an array is required).
|
IPAddressPartStringCollection |
toAllStringCollection() |
IPv4Address |
toBroadcastAddress()
The broadcast address has the same prefix but a host that is all 1 bits.
|
Inet4Address |
toInetAddress()
Converts the lowest value of this address to an InetAddress
|
String |
toInetAtonString(IPv4Address.inet_aton_radix radix)
Returns a string like the inet_aton style string
|
String |
toInetAtonString(IPv4Address.inet_aton_radix radix,
int joinedCount) |
IPv4Address |
toIPv4()
If this address is IPv4, or can be converted to IPv4, returns that
IPv4Address. |
IPv6Address |
toIPv6()
Returns this address converted to IPv6.
|
IPv4Address |
toMaxHost()
Returns the segment series with a host of all ones.
|
IPv4Address |
toMaxHost(int prefixLength)
Produces the series with host values of all one bits for the given prefix length.
|
IPv4Address |
toNetworkAddress()
The network address has the same prefix but a zero host.
|
static String |
toNormalizedString(IPv4AddressNetwork network,
Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider,
Integer prefixLength)
Creates the normalized string for an address without having to create the address objects first.
|
IPv4Address |
toPrefixBlock()
Returns the subnet associated with the prefix length of this address.
|
IPv4Address |
toPrefixBlock(int networkPrefixLength)
Returns the segment series of the same length that spans all hosts.
|
String |
toSegmentedBinaryString()
Writes this IP address segment series as a segments of binary values preceded by the "0b" prefix.
|
IPv4AddressSeqRange |
toSequentialRange()
Creates a sequential range instance from the lowest and highest addresses in this subnet
|
IPv4AddressSeqRange |
toSequentialRange(IPAddress other)
Deprecated.
|
IPAddressPartStringCollection |
toStandardStringCollection() |
IPAddressPartStringCollection |
toStringCollection(IPAddressSection.IPStringBuilderOptions opts) |
IPAddressPartStringCollection |
toStringCollection(IPv4AddressSection.IPv4StringBuilderOptions opts) |
String |
toUNCHostName()
Generates the Microsoft UNC path component for this address
|
Inet4Address |
toUpperInetAddress()
Converts the highest value of this address to an InetAddress.
|
IPv4Address |
toZeroHost()
Returns the segment series with a host of zero, the host being the bits following the prefix length.
|
IPv4Address |
toZeroHost(int prefixLength)
Produces the series with host values of 0 for the given prefix length.
|
IPv4Address |
toZeroNetwork()
Returns the segment series with a network of zero, the network being the bits within the prefix length.
|
int |
upperIntValue()
Returns the address (or highest value of the address if a subnet) as a signed integer
|
long |
upperLongValue()
Returns the address (or highest value of the address if a subnet) as a positive integer
|
IPv4Address |
withoutPrefixLength()
Provides the same address with no prefix.
|
applyToBounds, contains, contains, containsNonZeroHosts, getBitCount, getBitsPerSegment, getBlockMaskPrefixLength, getByteCount, getBytesPerSegment, getIPVersion, getLeadingBitCount, getMatchesSQLClause, getMatchesSQLClause, getMaxSegmentValue, getNetworkPrefixLength, getNonZeroHostCount, getSegmentCount, getSequentialBlockCount, getTrailingBitCount, includesMaxHost, includesMaxHost, includesZeroHost, includesZeroHost, isAnyLocal, isIPAddress, isIPv6, isSingleNetwork, isUnspecified, isZeroHost, isZeroHost, matches, matchesWithMask, mergeToDualPrefixBlocks, mergeToDualSequentialBlocks, overlaps, overlaps, prefixContains, removeBitCountPrefixLength, toAddressString, toAllStrings, toBinaryString, toCanonicalHostName, toCanonicalWildcardString, toCompressedWildcardString, toConvertedString, toDelimitedSQLStrs, toFullString, toHostName, toIPAddress, toNormalizedString, toNormalizedString, toNormalizedString, toNormalizedWildcardString, toOctalString, toPrefixLengthString, toReverseDNSLookupString, toSQLWildcardString, toStandardStrings, toStrings, toSubnetStringcontains, containsPrefixBlock, containsSinglePrefixBlock, defaultIpv4Network, defaultIpv6Network, defaultMACNetwork, equals, getBlockCount, getBytes, getBytes, getBytes, getCount, getDivisionCount, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getPrefixCount, getPrefixLength, getPrefixLengthForSingleBlock, getSegments, getSegments, getSegmentStrings, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, hashCode, includesMax, includesZero, isFullRange, isMACAddress, isMax, isMultiple, isPrefixBlock, isPrefixed, isSameAddress, isSequential, isSinglePrefixBlock, isZero, matchOrdered, matchUnordered, overlaps, prefixEquals, toCanonicalString, toCompressedString, toHexString, toMACAddress, toNormalizedString, toStringgetPrefixLenComparatorgetPrefixLength, isPrefixBlock, isPrefixedgetSegments, getSegments, getSegmentStrings, isOneBit, testBit, toCanonicalString, toCompressedStringgetBlockCount, getCount, getDivisionStrings, getPrefixCount, getPrefixCount, getPrefixLength, getSequentialBlockIndex, isMore, isPrefixBlock, isPrefixed, isSequential, isSinglePrefixBlockgetDivisionCounttoHexString, toNormalizedStringstream, streamcompareTo, containsPrefixBlock, containsSinglePrefixBlock, getBitsForCount, getBlockSize, getBytes, getBytes, getBytes, getMinPrefixLengthForBlock, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZeroisSequential, toCanonicalString, toNormalizedStringpublic static final char SEGMENT_SEPARATOR
public static final int BITS_PER_SEGMENT
public static final int BYTES_PER_SEGMENT
public static final int SEGMENT_COUNT
public static final int BYTE_COUNT
public static final int BIT_COUNT
public static final int DEFAULT_TEXTUAL_RADIX
public static final int MAX_VALUE_PER_SEGMENT
public static final int MAX_VALUE
public static final String REVERSE_DNS_SUFFIX
public IPv4Address(IPv4AddressSegment[] segments) throws AddressValueException
segments - the address segmentsAddressValueException - if segments is not length 4public IPv4Address(IPv4AddressSegment[] segments, Integer networkPrefixLength) throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration(),
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
segments - the address segmentsnetworkPrefixLength - AddressValueException - if segments is not length 4public IPv4Address(IPv4AddressSection section) throws AddressValueException
section - the address segmentsAddressValueException - if section does not have 4 segmentspublic IPv4Address(int address)
address - the 4 byte IPv4 addresspublic IPv4Address(int address,
Integer networkPrefixLength)
throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration(),
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
address - the 4 byte IPv4 addressnetworkPrefixLength - the CIDR network prefix length, which can be null for no prefixAddressValueExceptionpublic IPv4Address(Inet4Address inet4Address, Integer networkPrefixLength)
inet4Address - the java.net address objectpublic IPv4Address(Inet4Address inet4Address)
inet4Address - the java.net address objectpublic IPv4Address(byte[] bytes)
throws AddressValueException
bytes - the 4 byte IPv4 address in network byte order - if longer than 4 bytes the additional bytes must be zero, if shorter than 4 bytes then then the bytes are sign-extended to 4 bytes.AddressValueException - if bytes not equivalent to a 4 byte addresspublic IPv4Address(byte[] bytes,
int byteStartIndex,
int byteEndIndex)
throws AddressValueException
Similar to IPv4Address(byte[]) except that you can specify the start and end of the address in the given byte array.
bytes - AddressValueExceptionpublic IPv4Address(byte[] bytes,
Integer networkPrefixLength)
throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration(),
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
bytes - the 4 byte IPv4 address in network byte order - if longer than 4 bytes the additional bytes must be zero, if shorter than 4 bytes then the bytes are sign-extended to 4 bytes.networkPrefixLength - the CIDR network prefix length, which can be null for no prefixAddressValueException - if bytes not equivalent to a 4 byte addresspublic IPv4Address(byte[] bytes,
int byteStartIndex,
int byteEndIndex,
Integer networkPrefixLength)
throws AddressValueException
Similar to IPv4Address(byte[],Integer) except that you can specify the start and end of the address in the given byte array.
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration(),
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
bytes - the 4 byte IPv4 address - if longer than 4 bytes the additional bytes must be zero, if shorter than 4 bytes then the bytes are sign-extended to 4 bytes.networkPrefixLength - the CIDR network prefix length, which can be null for no prefixAddressValueException - if bytes not equivalent to a 4 byte addresspublic IPv4Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, Integer networkPrefixLength) throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration(),
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
lowerValueProvider - supplies the 1 byte lower values for each segmentupperValueProvider - supplies the 1 byte upper values for each segmentnetworkPrefixLength - the CIDR network prefix length, which can be null for no prefixAddressValueExceptionpublic IPv4Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider)
lowerValueProvider - supplies the 1 byte lower values for each segmentupperValueProvider - supplies the 1 byte upper values for each segmentpublic IPv4Address(Address.SegmentValueProvider valueProvider, Integer networkPrefixLength) throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration(),
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
valueProvider - supplies the 1 byte value for each segmentnetworkPrefixLength - the CIDR network prefix length, which can be null for no prefixAddressValueExceptionpublic IPv4Address(Address.SegmentValueProvider valueProvider)
valueProvider - supplies the 1 byte value for each segmentpublic IPv4AddressSection getSection()
IPAddressgetSection in interface AddressSegmentSeriesgetSection in interface IPAddressSegmentSeriesgetSection in class IPAddresspublic IPv4AddressSection getSection(int index)
AddressSegmentSeriesgetSection in interface AddressSegmentSeriesgetSection in interface IPAddressSegmentSeriesgetSection in class IPAddresspublic IPv4AddressSection getSection(int index, int endIndex)
AddressSegmentSeriesgetSection in interface AddressSegmentSeriesgetSection in interface IPAddressSegmentSeriesgetSection in class IPAddresspublic IPv4AddressSegment getDivision(int index)
getDivision in interface AddressDivisionSeriesgetDivision in interface IPAddressDivisionSeriesgetDivision in interface AddressStringDivisionSeriesgetDivision in interface IPAddressStringDivisionSeriespublic IPv4AddressSegment getSegment(int index)
AddressSegmentSeriesAddressDivisionSeries.getDivision(int), the difference being that all segments in a given series are the same bit count, while divisions can have variable length.getSegment in interface AddressSegmentSeriesgetSegment in interface IPAddressSegmentSeriespublic IPv4AddressSegment[] getSegments()
AddressSegmentSeriesAddressSegmentSeries.getSegment(int) and AddressSegmentSeries.getSegmentCount() instead when feasible.getSegments in interface AddressSegmentSeriesgetSegments in interface IPAddressSegmentSeriespublic IPAddressStringDivisionSeries[] getParts(IPAddressSection.IPStringBuilderOptions options)
IPAddresspublic IPAddressStringDivisionSeries[] getParts(IPv4AddressSection.IPv4StringBuilderOptions options)
public int getSegmentCount()
AddressSegmentSeriesgetSegmentCount in interface AddressSegmentSeriesgetSegmentCount in class Addresspublic int getByteCount()
AddressItemgetByteCount in interface AddressItemgetByteCount in class IPAddresspublic int getBitCount()
AddressItemgetBitCount in interface AddressDivisionSeriesgetBitCount in interface AddressItemgetBitCount in class Addresspublic IPv4Address toIPv4()
IPAddressIPv4Address. Otherwise, returns null.toIPv4 in class IPAddressIPAddress.isIPv4Convertible()public boolean isIPv4Convertible()
IPAddressIPv6Address.isIPv4Mapped()
You should also override IPAddress.toIPv4() to match the conversion.
This method returns true for all IPv4 addresses.isIPv4Convertible in class IPAddresspublic IPv6Address getIPv6Address(IPv6AddressSegment[] segs)
segs - public IPv6Address getIPv4MappedAddress()
public boolean isIPv6Convertible()
toIPv6() to match the conversion.isIPv6Convertible in class IPAddresstoIPv6()public IPv6Address toIPv6()
You can also use isIPv6Convertible() to determine convertibility. Both use an instance of IPAddressConverter.DefaultAddressConverter which uses IPv4-mapped address mappings from rfc 4038.
Override this method and IPv6Address.isIPv6Convertible() if you wish to map IPv4 to IPv6 according to the mappings defined by
in IPv6Address.isIPv4Compatible(), IPv6Address.isIPv4Mapped(), IPv6Address.is6To4() or some other mapping.
If you override this method, you should also override the isIPv6Convertible() method to match this behaviour,
and potentially also override the reverse conversion IPv6Address.toIPv4() in your IPv6Address subclass.
toIPv6 in class IPAddressIPv6Address. Otherwise, returns null.IPAddress.isIPv6Convertible()public IPv4Address toBroadcastAddress()
public IPv4Address toNetworkAddress()
public IPv4Address getLowerNonZeroHost()
IPAddressSegmentSeriesIPAddressSegmentSeries.getLower(), but will not return a series that has a prefix length and whose host value is zero.
If this series has no prefix length, returns the same series as IPAddressSegmentSeries.getLower().getLowerNonZeroHost in interface IPAddressSegmentSeriesgetLowerNonZeroHost in class IPAddresspublic IPv4Address getLower()
AddressSegmentSeriesgetLower in interface AddressSegmentSeriesgetLower in interface AddressComponentRangegetLower in interface IPAddressRangegetLower in interface IPAddressSegmentSeriesgetLower in class IPAddresspublic IPv4Address getUpper()
AddressSegmentSeriesgetUpper in interface AddressSegmentSeriesgetUpper in interface AddressComponentRangegetUpper in interface IPAddressRangegetUpper in interface IPAddressSegmentSeriesgetUpper in class IPAddresspublic int intValue()
public int upperIntValue()
public long longValue()
public long upperLongValue()
public IPv4Address replace(int startIndex, int endIndex, IPv4Address replacement, int replacementIndex)
startIndex - endIndex - replacement - replacementIndex - IndexOutOfBoundsExceptionpublic IPv4Address replace(int startIndex, IPv4AddressSection replacement)
startIndex - replacement - IndexOutOfBoundsExceptionpublic IPv4Address reverseBits(boolean perByte)
AddressSegmentSeriesreverseBits in interface AddressComponentreverseBits in interface AddressSegmentSeriesreverseBits in interface IPAddressSegmentSeriesreverseBits in class IPAddressperByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedpublic IPv4Address reverseBytes()
AddressSegmentSeriesreverseBytes in interface AddressComponentreverseBytes in interface AddressSegmentSeriesreverseBytes in interface IPAddressSegmentSeriesreverseBytes in class IPAddresspublic IPv4Address reverseBytesPerSegment()
AddressSegmentSeriesreverseBytesPerSegment in interface AddressSegmentSeriesreverseBytesPerSegment in interface IPAddressSegmentSeriesreverseBytesPerSegment in class IPAddresspublic IPv4Address reverseSegments()
AddressSegmentSeriesIncompatibleAddressException since all address series can reverse their segments.reverseSegments in interface AddressSegmentSeriesreverseSegments in interface IPAddressSegmentSeriesreverseSegments in class IPAddresspublic IPv4Address adjustPrefixBySegment(boolean nextSegment)
AddressSegmentSeries
Follows the same rules as AddressSegmentSeries.adjustPrefixLength(int):
When prefix length is increased, the bits moved within the prefix become zero.
When a prefix length is decreased, the bits moved outside the prefix become zero.
To avoid the zeroing behaviour, use AddressSegmentSeries.adjustPrefixBySegment(boolean, boolean) with second arg false.
adjustPrefixBySegment in interface AddressSegmentSeriesadjustPrefixBySegment in interface IPAddressSegmentSeriesadjustPrefixBySegment in class IPAddressnextSegment - whether to move prefix to previous or following segment boundarypublic IPv4Address adjustPrefixBySegment(boolean nextSegment, boolean zeroed)
AddressSegmentSeriesadjustPrefixBySegment in interface AddressSegmentSeriesadjustPrefixBySegment in interface IPAddressSegmentSeriesadjustPrefixBySegment in class IPAddressnextSegment - whether to move prefix to previous or following segment boundaryzeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original valuespublic IPv4Address adjustPrefixLength(int adjustment)
IPAddress
When prefix length is increased, the bits moved within the prefix become zero.
When the prefix is extended beyond the segment series boundary, it is removed.
When a prefix length is decreased, the bits moved outside the prefix become zero,
and if the entire host address contains the zero address,
then the resulting address is determined AddressNetwork.getPrefixConfiguration().
For example, 1.2.0.0/16 adjusted by -8 becomes 1.0.0.0/8.
1.2.0.0/16 adjusted by 8 becomes 1.2.0.0/24
adjustPrefixLength in interface AddressSegmentSeriesadjustPrefixLength in interface IPAddressSegmentSeriesadjustPrefixLength in class IPAddresspublic IPv4Address adjustPrefixLength(int adjustment, boolean zeroed)
AddressSegmentSeriesadjustPrefixLength in interface AddressSegmentSeriesadjustPrefixLength in interface IPAddressSegmentSeriesadjustPrefixLength in class IPAddressadjustment - the incrementzeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original valuespublic IPv4Address setPrefixLength(int prefixLength)
AddressSegmentSeries
If this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero.
For an alternative that does not set bits to zero, use AddressSegmentSeries.setPrefixLength(int, boolean) with the second argument as false.
When the prefix is extended beyond the segment series boundary, it is removed.
The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
setPrefixLength in interface AddressSegmentSeriessetPrefixLength in interface IPAddressSegmentSeriessetPrefixLength in class IPAddresspublic IPv4Address setPrefixLength(int prefixLength, boolean zeroed)
AddressSegmentSeriesWhen the prefix is extended beyond the segment series boundary, it is removed.
setPrefixLength in interface AddressSegmentSeriessetPrefixLength in interface IPAddressSegmentSeriessetPrefixLength in class IPAddresszeroed - whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.public IPv4Address setPrefixLength(int prefixLength, boolean zeroed, boolean zeroHostIsBlock) throws PrefixLenException
IPAddressIPAddress.setPrefixLength(int, boolean) and IPAddress.setPrefixLength(int)
use a value of true for zeroed and for zeroHostIsBlock.
For example, when zeroHostIsBlock is true, applying to 1.2.0.0 the prefix length 16 results in 1.2.*.*/16
Or if you start with 1.2.0.0/24, setting the prefix length to 16 results in a zero host followed by the existing prefix block, which is then converted to a full prefix block, 1.2.*.*/16
When both zeroed and zeroHostIsBlock are true, applying the prefiix length of 16 to 1.2.4.0/24 also results in a zero host followed by the existing prefix block, which is then converted to a full prefix block, 1.2.*.*/16.
When both zeroed and zeroHostIsBlock are false, the resulting address always encompasses the same set of addresses as the original, albeit with a different prefix length.
setPrefixLength in class IPAddressPrefixLenException@Deprecated public IPv4Address applyPrefixLength(int networkPrefixLength) throws PrefixLenException
AddressSegmentSeries
Similar to AddressSegmentSeries.setPrefixLength(int) except that prefix lengths are never increased.
When this series already has a prefix length that is less than or equal to the requested prefix length, this series is returned.
Otherwise the returned series has the given prefix length.
The bits moved outside the prefix will become zero in the returned series.
applyPrefixLength in interface AddressSegmentSeriesapplyPrefixLength in interface IPAddressSegmentSeriesapplyPrefixLength in class IPAddressPrefixLenExceptionAddressSegmentSeries.setPrefixLength(int)@Deprecated public IPv4Address removePrefixLength(boolean zeroed)
AddressSegmentSeriesAddressSegmentSeries.removePrefixLength()removePrefixLength in interface AddressSegmentSeriesremovePrefixLength in interface IPAddressSegmentSeriesremovePrefixLength in class IPAddresszeroed - whether the bits outside the prefix become zeropublic IPv4Address withoutPrefixLength()
AddressSegmentSeries
Use AddressSegmentSeries.removePrefixLength() as an alternative that deletes the host at the same time by zeroing the host values.
withoutPrefixLength in interface AddressSegmentSerieswithoutPrefixLength in interface IPAddressSegmentSerieswithoutPrefixLength in class IPAddress@Deprecated public IPv4Address removePrefixLength()
AddressSegmentSeries
If the series already has a prefix length, the bits outside the prefix become zero.
Use AddressSegmentSeries.withoutPrefixLength() to remove the prefix length without changing the series values.
Equivalent to calling removePrefixLength(true)
removePrefixLength in interface AddressSegmentSeriesremovePrefixLength in interface IPAddressSegmentSeriesremovePrefixLength in class IPAddressfor an alternative which does not change the address series values.public Iterator<IPv4AddressSegment[]> segmentsNonZeroHostIterator()
IPAddressSegmentSeriessegmentsNonZeroHostIterator in interface IPAddressSegmentSeriespublic Iterator<IPv4AddressSegment[]> segmentsIterator()
AddressSegmentSeriessegmentsIterator in interface AddressSegmentSeriessegmentsIterator in interface IPAddressSegmentSeriespublic AddressComponentRangeSpliterator<IPv4Address,IPv4AddressSegment[]> segmentsSpliterator()
AddressSegmentSeriessegmentsSpliterator in interface AddressSegmentSeriessegmentsSpliterator in interface IPAddressSegmentSeriespublic Stream<IPv4AddressSegment[]> segmentsStream()
AddressSegmentSeriesBaseStream.parallel() on the returned stream.segmentsStream in interface AddressSegmentSeriessegmentsStream in interface IPAddressSegmentSeriespublic Iterator<IPv4Address> iterator()
AddressComponentRangeAn address component can represent an individual segment, address, or section, or it can represent multiple, typically a subnet of addresses or a range of segment or section values.
Call AddressItem.isMultiple() to determine if this instance represents multiple, or AddressItem.getCount() for the count.
iterator in interface AddressSegmentSeriesiterator in interface AddressComponentRangeiterator in interface IPAddressRangeiterator in interface IPAddressSegmentSeriesiterator in interface Iterable<IPv4Address>iterator in class IPAddresspublic AddressComponentSpliterator<IPv4Address> spliterator()
AddressComponentRangespliterator in interface AddressComponentspliterator in interface AddressSegmentSeriesspliterator in interface AddressComponentRangespliterator in interface IPAddressRangespliterator in interface IPAddressSegmentSeriesspliterator in interface Iterable<IPv4Address>spliterator in class IPAddresspublic Stream<IPv4Address> stream()
AddressComponentRangeBaseStream.parallel() on the returned stream.stream in interface AddressSegmentSeriesstream in interface AddressComponentRangestream in interface IPAddressSegmentSeriesstream in class IPAddresspublic Iterator<IPv4Address> nonZeroHostIterator()
IPAddressSegmentSeriesnonZeroHostIterator in interface IPAddressSegmentSeriesnonZeroHostIterator in class IPAddresspublic Iterator<IPv4Address> prefixBlockIterator()
AddressSegmentSeries
If the series has no prefix length, then this is equivalent to AddressSegmentSeries.iterator()
prefixBlockIterator in interface AddressSegmentSeriesprefixBlockIterator in interface IPAddressSegmentSeriesprefixBlockIterator in class IPAddresspublic AddressComponentSpliterator<IPv4Address> prefixBlockSpliterator()
AddressSegmentSeriesprefixBlockSpliterator in interface AddressSegmentSeriesprefixBlockSpliterator in interface IPAddressSegmentSeriesprefixBlockSpliterator in class IPAddresspublic Stream<IPv4Address> prefixBlockStream()
AddressSegmentSeriesBaseStream.parallel() on the returned stream.prefixBlockStream in interface AddressSegmentSeriesprefixBlockStream in interface IPAddressSegmentSeriesprefixBlockStream in class IPAddresspublic Iterator<IPv4Address> prefixBlockIterator(int prefixLength)
IPAddressRangeprefixBlockIterator in interface IPAddressRangepublic AddressComponentSpliterator<IPv4Address> prefixBlockSpliterator(int prefixLength)
IPAddressRangeprefixBlockSpliterator in interface IPAddressRangepublic Stream<IPv4Address> prefixBlockStream(int prefixLength)
IPAddressRangeBaseStream.parallel() on the returned stream.prefixBlockStream in interface IPAddressRangepublic Iterator<IPv4Address> prefixIterator()
AddressSegmentSeries
If the series has no prefix length, then this is equivalent to AddressSegmentSeries.iterator()
prefixIterator in interface AddressSegmentSeriesprefixIterator in interface IPAddressSegmentSeriesprefixIterator in class IPAddresspublic AddressComponentSpliterator<IPv4Address> prefixSpliterator()
AddressSegmentSeriesprefixSpliterator in interface AddressSegmentSeriesprefixSpliterator in interface IPAddressSegmentSeriesprefixSpliterator in class IPAddresspublic Stream<IPv4Address> prefixStream()
AddressSegmentSeriesBaseStream.parallel() on the returned stream.prefixStream in interface AddressSegmentSeriesprefixStream in interface IPAddressSegmentSeriesprefixStream in class IPAddresspublic Iterator<IPv4Address> prefixIterator(int prefixLength)
IPAddressRangeprefixIterator in interface IPAddressRangepublic AddressComponentSpliterator<IPv4Address> prefixSpliterator(int prefixLength)
IPAddressRangeprefixSpliterator in interface IPAddressRangepublic Stream<IPv4Address> prefixStream(int prefixLength)
IPAddressRangeBaseStream.parallel() on the returned stream.prefixStream in interface IPAddressRangepublic Iterator<IPv4Address> blockIterator(int segmentCount)
IPAddressSegmentSeriesFor instance, given the IPv4 subnet 1-2.3-4.5-6.7, given the count argument 2, it will iterate through 1.3.5-6.7, 1.4.5-6.7, 2.3.5-6.7, 2.4.5-6.7
blockIterator in interface IPAddressSegmentSeriesblockIterator in class IPAddresspublic AddressComponentSpliterator<IPv4Address> blockSpliterator(int segmentCount)
IPAddressSegmentSeriesblockSpliterator in interface IPAddressSegmentSeriesblockSpliterator in class IPAddresspublic Stream<IPv4Address> blockStream(int segmentCount)
IPAddressSegmentSeriesBaseStream.parallel() on the returned stream.blockStream in interface IPAddressSegmentSeriesblockStream in class IPAddresspublic Iterator<IPv4Address> sequentialBlockIterator()
IPAddressSegmentSeriesIPAddressSegmentSeries.blockIterator(int) with that segment count.
For instance, given the IPv4 subnet 1-2.3-4.5-6.7-8, it will iterate through 1.3.5.7-8, 1.3.6.7-8, 1.4.5.7-8, 1.4.6.7-8, 2.3.5.7-8, 2.3.6.7-8, 2.4.6.7-8, 2.4.6.7-8.
Use IPAddressSegmentSeries.getSequentialBlockCount() to get the count of iterated elements.
sequentialBlockIterator in interface IPAddressSegmentSeriessequentialBlockIterator in class IPAddresspublic AddressComponentSpliterator<IPv4Address> sequentialBlockSpliterator()
IPAddressSegmentSeriessequentialBlockSpliterator in interface IPAddressSegmentSeriessequentialBlockSpliterator in class IPAddresspublic Stream<IPv4Address> sequentialBlockStream()
IPAddressSegmentSeriesBaseStream.parallel() on the returned stream.
Use IPAddressSegmentSeries.getSequentialBlockCount() to get the count of streamed elements.
sequentialBlockStream in interface IPAddressSegmentSeriessequentialBlockStream in class IPAddresspublic Iterable<IPv4Address> getIterable()
AddressComponentRangeAddressComponentRange.iterator() directly.getIterable in interface AddressSegmentSeriesgetIterable in interface AddressComponentRangegetIterable in interface IPAddressRangegetIterable in interface IPAddressSegmentSeriesgetIterable in class IPAddresspublic IPv4Address increment(long increment)
AddressSegmentSeriesIf the subnet has multiple values and the increment exceeds the subnet size, then the amount by which it exceeds the size - 1 is added to the upper series of the range (the final iterator value).
If the increment is negative, it is added to the lower series of the range (the first iterator value).
If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.
If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the AddressSegmentSeries.iterator()
For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on.
A negative increment added to the subnet count is equivalent to the same number of values preceding the upper bound of the iterator.
For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.
An increment of size count gives you the series just above the highest series of the subnet. To get the series just below the lowest series of the subnet, use the increment -1.
increment in interface AddressSegmentSeriesincrement in interface IPAddressSegmentSeriesincrement in class IPAddresspublic IPv4Address incrementBoundary(long increment)
AddressSegmentSeriesAddressSegmentSeries.getUpper()) in the subnet range to produce a new series.
If the given increment is negative, adds the value to the lower series (AddressSegmentSeries.getLower()) in the subnet range to produce a new series.
If the increment is zero, returns this.
In the case where the series is a single value, this simply returns the address produced by adding the given increment to this address series.
incrementBoundary in interface AddressSegmentSeriesincrementBoundary in interface IPAddressSegmentSeriesincrementBoundary in class IPAddresspublic Long enumerateIPv4(IPv4Address other)
Equivalent to enumerate(IPAddress) but returns a Long rather than a BigInteger.
public BigInteger enumerate(Address other)
AddressDetermines how many address elements of a subnet precede the given address element, if the address is in the subnet. If above the subnet range, it is the distance to the upper boundary added to the subnet address count less one, and if below the subnet range, the distance to the lower boundary.
In other words, if the given address is not in the subnet but above it, returns the number of addresses preceding the address from the upper subnet boundary, added to one less than the total number of subnet addresses. If the given address is not in the subnet but below it, returns the number of addresses following the address to the lower subnet boundary.
enumerate returns null when the argument is a multi-valued subnet. The argument must be an individual address.
When this address is also single-valued, the returned value is the distance (difference) between this address and the argument address.
enumerate is the inverse of the increment method:
If the given address does not have the same version or type as this subnet or address, then null is returned.
public BigInteger enumerate(IPAddress other)
IPAddress
For more details, see the equivalent method Address.enumerate(Address).
This method satisfies the implementation of IPAddressRange.
enumerate in interface IPAddressRangeenumerate in class IPAddresspublic IPv4AddressNetwork getNetwork()
AddressComponentgetNetwork in interface AddressComponentgetNetwork in interface IPAddressStringDivisionSeriesgetNetwork in interface IPAddressSegmentSeriesgetNetwork in class IPAddresspublic IPv6AddressNetwork getIPv6Network()
getIPv4MappedAddress() and getIPv6Address(IPv6AddressSegment[])public IPv4Address intersect(IPAddress other) throws AddressConversionException
IPAddressThis is also known as the conjunction of the two sets of addresses.
If the address is not the same version, the default conversion will be applied using IPAddress.toIPv4() or IPAddress.toIPv6(), and it that fails, AddressConversionException will be thrown.
intersect in class IPAddressAddressConversionException - if the address argument could not be converted to the same address version as thispublic IPv4Address[] subtract(IPAddress other) throws AddressConversionException
IPAddressComputes the subnet difference, the set of addresses in this address subnet but not in the provided subnet. This is also known as the relative complement of the given argument in this subnet.
If the address is not the same version, the default conversion will be applied using IPAddress.toIPv4() or IPAddress.toIPv6(), and it that fails, AddressConversionException will be thrown.
subtract in class IPAddressAddressConversionException - if the address argument could not be converted to the same address version as thispublic IPv4Address toZeroHost()
IPAddressSegmentSeries
The default behaviour is that the resultant series will have the same prefix length.
The resultant series will not have a prefix length if AddressNetwork.getPrefixConfiguration() is AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS.
For instance, you can get the network address for a subnet as follows:
String addrStr = "1.2.3.4/16";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress networkAddress = address.toZeroHost(); //1.2.0.0
toZeroHost in interface IPAddressSegmentSeriestoZeroHost in class IPAddressIPAddressSegmentSeries.toZeroNetwork()public IPv4Address toZeroHost(int prefixLength)
IPAddressSegmentSeriesIf this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
This is nearly equivalent to doing the mask (bitwise conjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of 0, but not necessarily the intervening values.
For instance, you can get the network address for a subnet of prefix length 16 as follows:
String addrStr = "1.2.3.4";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress networkAddress = address.toZeroHost(16); //1.2.0.0
toZeroHost in interface IPAddressSegmentSeriestoZeroHost in class IPAddresspublic IPv4Address toZeroNetwork()
IPAddressSegmentSeries
The default behaviour is that the resultant series will have the same prefix length.
The resultant series will not have a prefix length if AddressNetwork.getPrefixConfiguration() is AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS.
toZeroNetwork in interface IPAddressSegmentSeriestoZeroNetwork in class IPAddressIPAddressSegmentSeries.toZeroHost()public IPv4Address toMaxHost()
IPAddressSegmentSeries
The resultant series will have the same prefix length if AddressNetwork.getPrefixConfiguration() is not AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS,
otherwise it will no longer have a prefix length.
For instance, you can get the broadcast address for a subnet as follows:
String addrStr = "1.2.3.4/16";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress broadcastAddress = address.toMaxHost(); //1.2.255.255
toMaxHost in interface IPAddressSegmentSeriestoMaxHost in class IPAddresspublic IPv4Address toMaxHost(int prefixLength)
IPAddressSegmentSeriesIf this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
This is nearly equivalent to doing the bitwise or (bitwise disjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of all ones, but not necessarily the intervening values.
For instance, you can get the broadcast address for a subnet of prefix length 16 as follows:
String addrStr = "1.2.3.4";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress broadcastAddress = address.toMaxHost(16); //1.2.255.255
toMaxHost in interface IPAddressSegmentSeriestoMaxHost in class IPAddresspublic IPv4Address mask(IPAddress mask, boolean retainPrefix) throws IncompatibleAddressException, AddressConversionException
IPAddress
If the mask is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses
that cannot be represented as a contiguous range within each segment, then IncompatibleAddressException is thrown.
mask in class IPAddressIncompatibleAddressException - if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException - if the address argument could not be converted to the same address version as thispublic IPv4Address mask(IPAddress mask) throws IncompatibleAddressException, AddressConversionException
IPAddressIPAddress.mask(IPAddress, boolean) with the second argument as false.
If the mask is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
mask in class IPAddressIncompatibleAddressException - if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException - if the address argument could not be converted to the same address version as thispublic IPv4Address maskNetwork(IPAddress mask, int networkPrefixLength) throws IncompatibleAddressException, PrefixLenException, AddressConversionException
IPAddressAny existing prefix length is removed as the mask and new prefix length is applied to all individual addresses.
If the mask is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses
that cannot be represented as a contiguous range within each segment, then IncompatibleAddressException is thrown.
maskNetwork in class IPAddressIncompatibleAddressException - if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException - if the address argument could not be converted to the same address version as thisPrefixLenExceptionpublic IPv4Address bitwiseOr(IPAddress mask, boolean retainPrefix) throws IncompatibleAddressException, AddressConversionException
IPAddress
The mask is applied to all individual addresses, similar to how the method IPAddress.mask(IPAddress, boolean) applies the bitwise conjunction.
Any existing prefix length is removed beforehand. If the retainPrefix argument is true, then the existing prefix length will be applied to the result.
If the mask is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
If you wish to mask a section of the network, use IPAddress.bitwiseOrNetwork(IPAddress, int)
For instance, you can get the broadcast address for a subnet as follows:
String addrStr = "1.2.3.4/16";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress hostMask = address.getNetwork().getHostMask(address.getNetworkPrefixLength());//0.0.255.255
IPAddress broadcastAddress = address.bitwiseOr(hostMask); //1.2.255.255
bitwiseOr in class IPAddressIncompatibleAddressException - if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException - if the address argument could not be converted to the same address version as thispublic IPv4Address bitwiseOr(IPAddress mask) throws IncompatibleAddressException, AddressConversionException
IPAddressIPAddress.bitwiseOr(IPAddress, boolean) with the second argument as false.
If the mask is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
bitwiseOr in class IPAddressIncompatibleAddressException - if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException - if the address argument could not be converted to the same address version as thispublic IPv4Address bitwiseOrNetwork(IPAddress mask, int networkPrefixLength) throws IncompatibleAddressException, PrefixLenException, AddressConversionException
IPAddress
If the mask is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
Any existing prefix length is dropped for the new prefix length and the mask is applied up to the end the new prefix length.
It is similar to how the IPAddress.maskNetwork(IPAddress, int) method does the bitwise conjunction.
bitwiseOrNetwork in class IPAddressnetworkPrefixLength - the new prefix length for the addressIncompatibleAddressException - if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException - if the address argument could not be converted to the same address version as thisPrefixLenExceptionpublic IPv4Address getHostMask()
IPAddressSegmentSeriesgetHostMask in interface IPAddressSegmentSeriesgetHostMask in class IPAddresspublic IPv4Address getNetworkMask()
IPAddressSegmentSeriesgetNetworkMask in interface IPAddressSegmentSeriesgetNetworkMask in class IPAddresspublic IPv4AddressSection getNetworkSection()
IPAddressSegmentSeriesgetNetworkSection in interface IPAddressSegmentSeriespublic IPv4AddressSection getNetworkSection(int networkPrefixLength) throws PrefixLenException
IPAddressSegmentSeriesgetNetworkSection in interface IPAddressSegmentSeriesPrefixLenExceptionpublic IPv4AddressSection getNetworkSection(int networkPrefixLength, boolean withPrefixLength) throws PrefixLenException
IPAddressSegmentSeriesgetNetworkSection in interface IPAddressSegmentSerieswithPrefixLength - whether the resulting section will have networkPrefixLength as the associated prefix length or notPrefixLenExceptionpublic IPv4AddressSection getHostSection()
IPAddressSegmentSeriesgetHostSection in interface IPAddressSegmentSeriespublic IPv4AddressSection getHostSection(int networkPrefixLength) throws PrefixLenException
IPAddressSegmentSeriesgetHostSection in interface IPAddressSegmentSeriesPrefixLenExceptionpublic IPv4Address toPrefixBlock()
IPAddressFor example, if the address is 1.2.3.4/16 it returns the subnet 1.2.*.* /16
toPrefixBlock in interface AddressSegmentSeriestoPrefixBlock in interface IPAddressSegmentSeriestoPrefixBlock in class IPAddresspublic IPv4Address toPrefixBlock(int networkPrefixLength) throws PrefixLenException
IPAddressSegmentSeriestoPrefixBlock in interface IPAddressSegmentSeriestoPrefixBlock in class IPAddressPrefixLenExceptionpublic IPv4Address assignPrefixForSingleBlock()
IPAddressIf no such prefix length exists, returns null.
Examples:
1.2.3.4 returns 1.2.3.4/32
1.2.*.* returns 1.2.0.0/16
1.2.*.0/24 returns 1.2.0.0/16
1.2.*.4 returns null
1.2.252-255.* returns 1.2.252.0/22
1.2.3.4/x returns the same address
assignPrefixForSingleBlock in interface IPAddressSegmentSeriesassignPrefixForSingleBlock in class IPAddressIPAddressSegmentSeries.toPrefixBlock(),
IPAddressSegmentSeries.assignMinPrefixForBlock()public IPv4Address assignMinPrefixForBlock()
IPAddressassignMinPrefixForBlock in interface IPAddressSegmentSeriesassignMinPrefixForBlock in class IPAddressIPAddressSegmentSeries.toPrefixBlock(),
IPAddressSegmentSeries.assignPrefixForSingleBlock()public IPv4Address coverWithPrefixBlock()
IPAddressSegmentSeriescoverWithPrefixBlock in interface IPAddressRangecoverWithPrefixBlock in interface IPAddressSegmentSeriespublic IPv4Address coverWithPrefixBlock(IPAddress other) throws AddressConversionException
IPAddress
If the other address is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
When you have multiple subnets, cover with:
IPAddress block = subnet0.applyToBounds(IPAddress::coverWithPrefixBlock, subnet1, subnet2, ...);
See IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
coverWithPrefixBlock in class IPAddressAddressConversionExceptionpublic IPv4Address[] spanWithPrefixBlocks()
Unlike spanWithPrefixBlocks(IPAddress) this method only includes addresses that are a part of this subnet.
spanWithPrefixBlocks in interface IPAddressRangespanWithPrefixBlocks in interface IPAddressSegmentSeriespublic IPv4Address[] spanWithPrefixBlocks(IPAddress other) throws AddressConversionException
IPAddress
If the other address is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
The resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
From the list of returned subnets you can recover the original range (this to other) by converting each to IPAddressRange with IPAddress.toSequentialRange()
and them joining them into a single range with IPAddressSeqRange.join(IPAddressSeqRange...)
When you have multiple subnets, span with:
IPAddress blocks[] = subnet0.applyToBounds(IPAddress::spanWithPrefixBlocks, subnet1, subnet2, ...);
See IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
spanWithPrefixBlocks in class IPAddressAddressConversionExceptionpublic IPv4Address[] spanWithSequentialBlocks() throws AddressConversionException
This array can be shorter than that produced by spanWithPrefixBlocks() and is never longer.
Unlike spanWithSequentialBlocks(IPAddress) this method only includes addresses that are a part of this subnet.
spanWithSequentialBlocks in interface IPAddressRangespanWithSequentialBlocks in interface IPAddressSegmentSeriesAddressConversionExceptionpublic IPv4Address[] spanWithSequentialBlocks(IPAddress other) throws AddressConversionException
IPAddressIndividual block subnets come in the form 1-3.1-4.5.6-8, however that particular subnet is not sequential since address 1.1.5.8 is in the subnet, the next sequential address 1.1.5.9 is not in the subnet, and a higher address 1.2.5.6 is in the subnet. Blocks are sequential when the first segment with a range of values is followed by segments that span all values.
If the other address is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
The resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
From the list of returned subnets you can recover the original range (this and other) by converting each to IPAddressRange with IPAddress.toSequentialRange()
and them joining them into a single range with IPAddressSeqRange.join(IPAddressSeqRange...)
When you have multiple subnets, span with:
IPAddress blocks[] = subnet0.applyToBounds(IPAddress::spanWithSequentialBlocks, subnet1, subnet2, ...);
See IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
spanWithSequentialBlocks in class IPAddressAddressConversionExceptionpublic IPv4AddressSeqRange spanWithRange(IPAddress other) throws AddressConversionException
IPAddress
If the other address is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
When you have multiple subnets, span with:
IPAddressSeqRange range = subnet0.applyToBounds(IPAddress::spanWithRange, subnet1, subnet2, ...);
See IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
spanWithRange in class IPAddressAddressConversionExceptionpublic IPv4Address[] mergeToPrefixBlocks(IPAddress... addresses) throws AddressConversionException
IPAddress
For the smallest list of subnets use IPAddress.mergeToSequentialBlocks(IPAddress...).
If any other address in the list is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6(),
which can result in AddressConversionException
The resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
In version 5.3.1 and earlier, the result was sorted from single address to smallest blocks to largest blocks.
For that ordering, sort with IPAddressSegmentSeries.getPrefixLenComparator():
Arrays.sort(result, IPAddressSegmentSeries.getPrefixLenComparator());
The merging process works with sequential blocks. CIDR prefix subnets have just a single sequential block, as does individual addresses. So this method works efficiently for most conventionally-used subnets.
For example, the subnet ::*:*:*:1-ffff has 281474976710656 sequential blocks.
Just like you should avoid iterating through such a large number of blocks,
you should avoid using this method to merge such a subnet,
rather than a subnet like ::1-ffff:*:*:*:* which has 1 sequential block,
or the subnet ::1-ffff:1-ffff:*:*:*:* which has 65535 sequential blocks.
You can use IPAddress.getSequentialBlockCount() to get the sequential block count.
There are alternatives ways to merge into prefix blocks available in this library. Typically this method is most efficient when merging CIDR prefix blocks and/or individual addresses, which is likely to be the case for most users most of the time. It converts to CIDR prefix blocks prior to merging, if not CIDR prefix blocks or individual addresses already.
When merging a large number of blocks that are not prefix blocks nor individual addresses,
it may be more efficient to merge first and then convert to CIDR prefix blocks afterwards.
You can use IPAddress.mergeToSequentialBlocks(IPAddress...) to merge,
and then span each merged element in the result with IPAddressSegmentSeries.spanWithPrefixBlocks(),
giving the same result as this method.
Sequential ranges provide another option.
You can convert to sequential blocks first with IPAddress.sequentialBlockIterator(),
then convert each sequential block to IPAddressSeqRange with IPAddress.toSequentialRange(),
then join those sequential ranges with IPAddressSeqRange.join(IPAddressSeqRange...),
then convert them to CIDR prefix blocks with IPAddressSeqRange.spanWithPrefixBlocks(),
giving the same result as this method.
mergeToPrefixBlocks in class IPAddressaddresses - the addresses to merge with thisAddressConversionExceptionpublic IPv4Address[] mergeToSequentialBlocks(IPAddress... addresses) throws AddressConversionException
IPAddressBlock subnets come in the form 1-3.1-4.5.6-8, however that subnet is not sequential since address 1.1.5.8 is in the subnet, the next sequential address 1.1.5.9 is not in the subnet, and a higher address 1.2.5.6 is in the subnet. Blocks are sequential when the first segment with a range of values is followed by segments that span all values.
This list will eliminate overlaps to produce the smallest list of sequential block subnets, which is the same size or smaller than the list of prefix blocks produced by IPAddress.mergeToPrefixBlocks(IPAddress...)
If the incoming blocks are not sequential, the result could be a longer list, since the list is divided into sequential blocks before merging.
If any other address in the list is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6(),
which can result in AddressConversionException
The resulting array is sorted by lower address, regardless of the size of each prefix block.
In version 5.3.1 and earlier, the result was sorted from single address to smallest blocks to largest blocks.
For that ordering, sort with IPAddressSegmentSeries.getPrefixLenComparator():
Arrays.sort(result, IPAddressSegmentSeries.getPrefixLenComparator());
See the javadoc for IPAddress.mergeToPrefixBlocks(IPAddress...) for some alternatives for merging subnets.
mergeToSequentialBlocks in class IPAddressaddresses - the addresses to merge with thisAddressConversionExceptionpublic Inet4Address toUpperInetAddress()
IPAddressIPAddress.toInetAddress()toUpperInetAddress in class IPAddresspublic Inet4Address toInetAddress()
IPAddresstoInetAddress in class IPAddress@Deprecated public IPv4AddressSeqRange toSequentialRange(IPAddress other)
IPAddress
If the other address is a different version than this, then the default conversion is applied to the other address first using IPAddress.toIPv4() or IPAddress.toIPv6()
When you have multiple subnets, create a range from lowest to highest with:
IPAddressSeqRange range = subnet0.applyToBounds(IPAddress::toSequentialRange, subnet1, subnet2, ...);
See IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
toSequentialRange in class IPAddresspublic IPv4AddressSeqRange toSequentialRange()
IPAddress
The two will represent the same set of individual addresses if and only if Address.isSequential() is true.
To get a series of ranges that represent the same set of individual addresses use the IPAddress.sequentialBlockIterator() (or IPAddress.prefixIterator()),
and apply this method to each iterated subnet.
If this represents just a single address then the returned instance covers just that single address as well.
toSequentialRange in interface IPAddressRangetoSequentialRange in class IPAddresspublic boolean isLocal()
IPAddresspublic boolean isLinkLocal()
IPAddressisLinkLocal in class IPAddressInetAddress.isLinkLocalAddress()public boolean isPrivate()
InetAddress.isSiteLocalAddress()public boolean isMulticast()
AddressisMulticast in class AddressInetAddress.isMulticastAddress()public boolean isLoopback()
isLoopback in class IPAddressInetAddress.isLoopbackAddress()public static String toNormalizedString(IPv4AddressNetwork network, Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, Integer prefixLength)
lowerValueProvider - upperValueProvider - prefixLength - network - use Address.defaultIpv4Network() if there is no custom network in usepublic String toInetAtonString(IPv4Address.inet_aton_radix radix)
public String toInetAtonString(IPv4Address.inet_aton_radix radix, int joinedCount) throws IncompatibleAddressException
IncompatibleAddressExceptionpublic String toSegmentedBinaryString()
IPAddressSegmentSeriestoSegmentedBinaryString in interface IPAddressSegmentSeriespublic String toUNCHostName()
IPAddresstoUNCHostName in class IPAddresspublic IPAddressPartStringCollection toStandardStringCollection()
toStandardStringCollection in class IPAddresspublic IPAddressPartStringCollection toAllStringCollection()
toAllStringCollection in class IPAddresspublic IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions opts)
toStringCollection in interface IPAddressSegmentSeriestoStringCollection in class IPAddresspublic IPAddressPartStringCollection toStringCollection(IPv4AddressSection.IPv4StringBuilderOptions opts)