public class IPv4Address extends IPAddress implements java.lang.Iterable<IPv4Address>
Modifier and Type | Class and Description |
---|---|
static class |
IPv4Address.inet_aton_radix |
static interface |
IPv4Address.IPv4AddressConverter |
IPAddress.IPVersion
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_PER_SEGMENT |
static java.lang.String |
REVERSE_DNS_SUFFIX |
static int |
SEGMENT_COUNT |
static char |
SEGMENT_SEPARATOR |
addressConverter, PREFIX_LEN_SEPARATOR
addressComparator, ALTERNATIVE_RANGE_SEPARATOR, ALTERNATIVE_RANGE_SEPARATOR_STR, ALTERNATIVE_SEGMENT_WILDCARD_STR, 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 lowerValueProvider,
Address.SegmentValueProvider upperValueProvider)
Constructs an IPv4 address or subnet.
|
IPv4Address(Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider,
java.lang.Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
IPv4Address(byte[] bytes)
Constructs an IPv4 address.
|
IPv4Address(byte[] bytes,
java.lang.Integer networkPrefixLength)
Constructs an IPv4 address or subnet.
|
IPv4Address(int address)
Constructs an IPv4 address.
|
IPv4Address(int address,
java.lang.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,
java.lang.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 |
adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.
|
IPv4Address |
applyPrefixLength(int networkPrefixLength)
Applies the given prefix length to create a new address.
|
IPv4Address |
bitwiseOr(IPAddress mask)
Does the bitwise disjunction with this address.
|
IPv4Address |
bitwiseOrNetwork(IPAddress mask,
int networkPrefixLength)
Does the bitwise disjunction with this address.
|
int |
getBitCount() |
int |
getByteCount()
returns the number of bytes in each of the address components represented by this instance
|
IPv4AddressSection |
getHostSection()
Generates the host section of the address.
|
IPv4AddressSection |
getHostSection(int networkPrefixLength)
Generates the host section of the address.
|
IPv6Address |
getIPv4MappedAddress() |
java.lang.Iterable<IPv4Address> |
getIterable()
Useful for using an instance in a "for-each loop".
|
static IPv4Address |
getLoopback() |
IPv4Address |
getLower()
If this represents an address with ranging values, returns an address representing the lower values of the range.
|
IPv4AddressNetwork |
getNetwork() |
IPv4AddressSection |
getNetworkSection()
Generates the network section of the address if the address is a CIDR prefix, otherwise it generates the entire address as a prefixed address with prefix matching the address bit length.
|
IPv4AddressSection |
getNetworkSection(int networkPrefixLength)
Generates the network section of the address.
|
IPv4AddressSection |
getNetworkSection(int networkPrefixLength,
boolean withPrefixLength)
Generates the network section of the address.
|
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
|
IPv4AddressSection |
getSection(int index,
int endIndex)
Gets the subsection from the series starting from the given index and ending just before the give endIndex
|
IPv4AddressSegment |
getSegment(int index) |
int |
getSegmentCount() |
IPv4AddressSegment[] |
getSegments() |
static java.lang.String[] |
getStandardLoopbackStrings() |
IPv4Address |
getUpper()
If this represents an address with ranging values, returns an address representing the upper values of the range
If this represents an address with a single value in each segment, returns this.
|
boolean |
isIPv4Convertible()
Determines whether this address can be converted to IPv4, if not IPv4 already.
|
boolean |
isIPv6Convertible()
Determines whether an address can be converted to IPv6, if not IPv6 already.
|
boolean |
isLinkLocal() |
boolean |
isLoopback() |
boolean |
isMulticast() |
boolean |
isSiteLocal() |
java.util.Iterator<IPv4Address> |
iterator()
An address component can represent a single segment, address, or section, or it can represent multiple,
typically a subnet or range of segment, address, or section values.
|
IPv4Address |
mask(IPAddress mask)
Applies the given mask to all addresses represented by this IPAddress.
|
IPv4Address |
maskNetwork(IPAddress mask,
int networkPrefixLength)
Applies the given mask up until the given prefix length to all addresses represented by this IPAddress.
|
static IPv4AddressNetwork |
network() |
IPv4Address |
removePrefixLength()
Removes the prefix.
|
IPv4Address |
removePrefixLength(boolean zeroed) |
IPv4Address |
reverseBits(boolean perByte)
Returns a new IPAddress which has 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.
|
java.util.Iterator<IPv4AddressSegment[]> |
segmentsIterator() |
IPv4Address |
setPrefixLength(int prefixLength)
Sets the prefix length.
|
IPv4Address |
setPrefixLength(int prefixLength,
boolean zeroed) |
IPv4Address[] |
subtract(IPAddress other)
Subtract the give 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() |
java.net.Inet4Address |
toInetAddress() |
java.lang.String |
toInetAtonString(IPv4Address.inet_aton_radix radix)
Returns a string like the inet_aton style string
|
java.lang.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.
|
IPAddressPartStringCollection |
toStandardStringCollection() |
IPAddressPartStringCollection |
toStringCollection(IPAddressSection.IPStringBuilderOptions opts) |
IPAddressPartStringCollection |
toStringCollection(IPv4AddressSection.IPv4StringBuilderOptions opts) |
java.lang.String |
toUNCHostName()
Generates the Microsoft UNC path component for this address
|
bitCount, bitsPerSegment, byteCount, contains, contains, from, from, from, from, getBitsPerSegment, getBytesPerSegment, getIPVersion, getLocalHost, getLoopback, getMaskPrefixLength, getMatchesSQLClause, getMatchesSQLClause, getMaxSegmentValue, getNetworkPrefixLength, getSegmentStrings, getStandardLoopbackStrings, isAnyLocal, isIPv4, isIPv6, isLocal, isMultipleByNetworkPrefix, isSameAddress, matches, maxSegmentValue, network, segmentCount, toAddressString, toAllStrings, toBinaryString, toCanonicalHostName, toCanonicalWildcardString, toCompressedWildcardString, toConvertedString, toDelimitedSQLStrs, toFullString, toHostName, toMinPrefixedEquivalent, toNormalizedString, toNormalizedWildcardString, toOctalString, toPrefixedEquivalent, toPrefixLengthString, toReverseDNSLookupString, toSQLWildcardString, toStandardStrings, toStrings, toSubnetString
compareTo, equals, getBytes, getBytes, getCount, getDivision, getDivisionCount, getEquivalentPrefix, getMinPrefix, getPrefixLength, getSegments, getSegments, getUpperBytes, getUpperBytes, hashCode, isFullRange, isMore, isMultiple, isMultipleByPrefix, isPrefixed, isRangeEquivalentToPrefix, isSameAddress, isZero, toCanonicalString, toCompressedString, toHexString, toNormalizedString, toString
public 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 java.lang.String REVERSE_DNS_SUFFIX
public IPv4Address(IPv4AddressSegment[] segments, java.lang.Integer networkPrefixLength)
segments
- the address segmentsnetworkPrefixLength
- java.lang.IllegalArgumentException
- if segments is not length 4public IPv4Address(IPv4AddressSegment[] segments)
segments
- the address segmentsjava.lang.IllegalArgumentException
- if segments is not length 4public IPv4Address(IPv4AddressSection section)
section
- the address segmentsjava.lang.IllegalArgumentException
- if section does not have 4 segmentspublic IPv4Address(int address)
address
- the 4 byte IPv4 addresspublic IPv4Address(int address, java.lang.Integer networkPrefixLength)
address
- the 4 byte IPv4 addressnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefixpublic IPv4Address(byte[] bytes)
bytes
- must be a 4 byte IPv4 addressjava.lang.IllegalArgumentException
- if bytes is not length 4public IPv4Address(byte[] bytes, java.lang.Integer networkPrefixLength)
bytes
- must be a 4 byte IPv4 addressnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefixpublic IPv4Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, java.lang.Integer networkPrefixLength)
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 prefixpublic 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 IPv4AddressSection getSection()
IPAddress
getSection
in class IPAddress
public IPv4AddressSection getSection(int index)
AddressSegmentSeries
getSection
in interface AddressSegmentSeries
getSection
in class IPAddress
public IPv4AddressSection getSection(int index, int endIndex)
AddressSegmentSeries
getSection
in interface AddressSegmentSeries
getSection
in class IPAddress
public IPv4AddressSegment getSegment(int index)
getSegment
in interface AddressSegmentSeries
getSegment
in class IPAddress
public IPv4AddressSegment[] getSegments()
getSegments
in interface AddressSegmentSeries
getSegments
in class IPAddress
public IPAddressStringDivisionSeries[] getParts(IPAddressSection.IPStringBuilderOptions options)
IPAddress
public IPAddressStringDivisionSeries[] getParts(IPv4AddressSection.IPv4StringBuilderOptions options)
public int getSegmentCount()
getSegmentCount
in interface AddressSegmentSeries
getSegmentCount
in class Address
public int getByteCount()
AddressComponent
getByteCount
in interface AddressComponent
getByteCount
in class IPAddress
public int getBitCount()
getBitCount
in interface AddressItem
getBitCount
in class Address
public IPv4Address toIPv4()
IPAddress
IPv4Address
. Otherwise, returns null.toIPv4
in class IPAddress
IPAddress.isIPv4Convertible()
public boolean isIPv4Convertible()
IPAddress
IPAddress.toIPv4()
to match the conversion.
This method returns true for all IPv4 addresses.isIPv4Convertible
in class IPAddress
public IPv6Address getIPv4MappedAddress()
public boolean isIPv6Convertible()
IPAddress
IPAddress.toIPv6()
to match the conversion.
This method returns true for all IPv6 addresses.isIPv6Convertible
in class IPAddress
toIPv6()
public IPv6Address toIPv6()
This uses isIPv6Convertible()
to determine convertibility, and that uses an instance of IPAddressConverter.DefaultAddressConverter
which uses IPv4-mapped address mappings from rfc 4038.
Override this method and IPv6Address.isIPv4Convertible()
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 IPAddress
IPv6Address
. Otherwise, returns null.public IPv4Address getLower()
IPAddress
getLower
in interface AddressComponent
getLower
in interface AddressSegmentSeries
getLower
in class IPAddress
public IPv4Address getUpper()
IPAddress
getUpper
in interface AddressComponent
getUpper
in interface AddressSegmentSeries
getUpper
in class IPAddress
public IPv4Address reverseBits(boolean perByte)
IPAddress
reverseBits
in interface AddressComponent
reverseBits
in interface AddressSegmentSeries
reverseBits
in class IPAddress
perByte
- if true, only the bits in each byte are reversed, if false, then all bits in the address are reversedpublic IPv4Address reverseBytes()
AddressSegmentSeries
reverseBytes
in interface AddressComponent
reverseBytes
in interface AddressSegmentSeries
reverseBytes
in class IPAddress
public IPv4Address reverseBytesPerSegment()
AddressSegmentSeries
reverseBytesPerSegment
in interface AddressSegmentSeries
reverseBytesPerSegment
in class IPAddress
public IPv4Address reverseSegments()
AddressSegmentSeries
reverseSegments
in interface AddressSegmentSeries
reverseSegments
in class IPAddress
public IPv4Address adjustPrefixBySegment(boolean nextSegment)
AddressSegmentSeries
adjustPrefixBySegment
in interface AddressSegmentSeries
adjustPrefixBySegment
in class IPAddress
public IPv4Address adjustPrefixLength(int adjustment)
AddressSegmentSeries
adjustPrefixLength
in interface AddressSegmentSeries
adjustPrefixLength
in class IPAddress
public IPv4Address setPrefixLength(int prefixLength)
AddressSegmentSeries
setPrefixLength
in interface AddressSegmentSeries
setPrefixLength
in class IPAddress
public IPv4Address setPrefixLength(int prefixLength, boolean zeroed)
setPrefixLength
in class IPAddress
public java.util.Iterator<IPv4Address> iterator()
AddressComponent
AddressItem.isMultiple()
to determine if this instance represents multiple.
This method iterates through the individual elements.iterator
in interface AddressComponent
iterator
in interface AddressSegmentSeries
iterator
in interface java.lang.Iterable<IPv4Address>
iterator
in class IPAddress
public java.lang.Iterable<IPv4Address> getIterable()
AddressComponent
AddressComponent.iterator()
directly.getIterable
in interface AddressComponent
getIterable
in interface AddressSegmentSeries
getIterable
in class IPAddress
public static IPv4AddressNetwork network()
public IPv4AddressNetwork getNetwork()
getNetwork
in class IPAddress
public static IPv4Address getLoopback()
public static java.lang.String[] getStandardLoopbackStrings()
public IPv4Address[] subtract(IPAddress other)
IPAddress
public IPv4Address applyPrefixLength(int networkPrefixLength) throws AddressTypeException
IPAddress
applyPrefixLength
in interface AddressSegmentSeries
applyPrefixLength
in class IPAddress
AddressTypeException
public IPv4Address removePrefixLength(boolean zeroed)
removePrefixLength
in class IPAddress
public IPv4Address removePrefixLength()
AddressSegmentSeries
removePrefixLength
in interface AddressSegmentSeries
removePrefixLength
in class IPAddress
public IPv4Address mask(IPAddress mask) throws AddressTypeException
IPAddress
AddressTypeException
is thrown.mask
in class IPAddress
AddressTypeException
public IPv4Address maskNetwork(IPAddress mask, int networkPrefixLength) throws AddressTypeException
IPAddress
AddressTypeException
is thrown.maskNetwork
in class IPAddress
AddressTypeException
public IPv4Address bitwiseOr(IPAddress mask) throws AddressTypeException
IPAddress
bitwiseOr
in class IPAddress
AddressTypeException
public IPv4Address bitwiseOrNetwork(IPAddress mask, int networkPrefixLength) throws AddressTypeException
IPAddress
bitwiseOrNetwork
in class IPAddress
networkPrefixLength
- the new prefix length for the addressAddressTypeException
public IPv4AddressSection getNetworkSection(int networkPrefixLength)
IPAddress
getNetworkSection
in class IPAddress
public IPv4AddressSection getNetworkSection(int networkPrefixLength, boolean withPrefixLength)
IPAddress
getNetworkSection
in class IPAddress
withPrefixLength
- whether the resulting section will have networkPrefixLength as the associated prefix length or notpublic IPv4AddressSection getNetworkSection()
IPAddress
getNetworkSection
in class IPAddress
public IPv4AddressSection getHostSection(int networkPrefixLength)
IPAddress
getHostSection
in class IPAddress
public IPv4AddressSection getHostSection()
IPAddress
getHostSection
in class IPAddress
public java.net.Inet4Address toInetAddress()
toInetAddress
in class IPAddress
public boolean isLinkLocal()
isLinkLocal
in class IPAddress
InetAddress.isLinkLocalAddress()
public boolean isSiteLocal()
isSiteLocal
in class IPAddress
InetAddress.isSiteLocalAddress()
public boolean isMulticast()
isMulticast
in class Address
InetAddress.isMulticastAddress()
public boolean isLoopback()
isLoopback
in class IPAddress
InetAddress.isLoopbackAddress()
public java.lang.String toInetAtonString(IPv4Address.inet_aton_radix radix)
public java.lang.String toInetAtonString(IPv4Address.inet_aton_radix radix, int joinedCount)
public java.lang.String toUNCHostName()
IPAddress
toUNCHostName
in class IPAddress
public IPAddressPartStringCollection toStandardStringCollection()
toStandardStringCollection
in class IPAddress
public IPAddressPartStringCollection toAllStringCollection()
toAllStringCollection
in class IPAddress
public IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions opts)
toStringCollection
in class IPAddress
public IPAddressPartStringCollection toStringCollection(IPv4AddressSection.IPv4StringBuilderOptions opts)
public java.util.Iterator<IPv4AddressSegment[]> segmentsIterator()
segmentsIterator
in interface AddressSegmentSeries
segmentsIterator
in class IPAddress