java.lang.Object
com.aoapps.net.InetAddress
- All Implemented Interfaces:
DtoFactory<InetAddress>
,Internable<InetAddress>
,Serializable
,Comparable<InetAddress>
public final class InetAddress
extends Object
implements Comparable<InetAddress>, Serializable, DtoFactory<InetAddress>, Internable<InetAddress>
Represents either an IPv4 or an IPv6 IP address.
The internal storage is always that of an IPv6 address.
IPv4 addresses are stored as IPv4-mapped addresses (::ffff:a.b.c.d
),
but their external representation is always dotted-decimal IPv4 notation (a.b.c.d
).
- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final InetAddress
static final InetAddress
static final InetAddress
static final InetAddress
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(InetAddress other) Sorts by address family then numeric address.boolean
Deprecated.Gets the type for this address.getDto()
long
getHigh()
Gets the high-order 64 bits of the numeric address.getIp()
Gets the numeric address as a 128-bit integer.long
getLow()
Gets the low-order 64 bits of the numeric address.int
hashCode()
intern()
Interns this IP much in the same fashion asString.intern()
.boolean
is6to4()
boolean
The IPv4 Broadcast (255.255.255.255/32
).boolean
boolean
boolean
isIPv4()
Deprecated.Please usegetProtocolFamily()
boolean
isIPv6()
Deprecated.Please usegetProtocolFamily()
boolean
boolean
boolean
boolean
boolean
isOrchid()
boolean
isTeredo()
boolean
boolean
Gets an optionally-bracketed String representation of this IP address.toString()
Converts this IP address to its String representation.static ValidationResult
Checks if the address is valid by callingparse(String)
and discarding the result.static InetAddress
valueOf
(long hi, long lo) Gets an IPv6 address from its numerical representation.static InetAddress
Gets an IPv6 address from its numerical representation.static InetAddress
Parses either an IPv4 or IPv6 address.
-
Field Details
-
UNSPECIFIED_IPV4
-
UNSPECIFIED_IPV6
-
LOOPBACK_IPV4
-
LOOPBACK_IPV6
-
-
Method Details
-
validate
Checks if the address is valid by callingparse(String)
and discarding the result.When enclosed in brackets
"[...]"
, will be parsed as an IPv6InetAddress
(seetoBracketedString()
).- See Also:
-
valueOf
Parses either an IPv4 or IPv6 address.When enclosed in brackets
"[...]"
, will be parsed as an IPv6InetAddress
(seetoBracketedString()
).- Parameters:
address
- whennull
, returnsnull
- Throws:
ValidationException
-
valueOf
Gets an IPv6 address from its numerical representation.- Parameters:
ip
- If ip is null, returns null.- See Also:
-
valueOf
Gets an IPv6 address from its numerical representation.- See Also:
-
equals
-
hashCode
public int hashCode() -
compareTo
Sorts by address family then numeric address.- Specified by:
compareTo
in interfaceComparable<InetAddress>
-
toString
Converts this IP address to its String representation. -
toBracketedString
Gets an optionally-bracketed String representation of this IP address. If IPv6, the address is surrounded by [...] -
intern
Interns this IP much in the same fashion asString.intern()
.- Specified by:
intern
in interfaceInternable<InetAddress>
- See Also:
-
getHigh
public long getHigh()Gets the high-order 64 bits of the numeric address.- See Also:
-
getLow
public long getLow()Gets the low-order 64 bits of the numeric address.- See Also:
-
getIp
Gets the numeric address as a 128-bit integer.- See Also:
-
getDto
- Specified by:
getDto
in interfaceDtoFactory<InetAddress>
-
isUnspecified
public boolean isUnspecified() -
isLoopback
public boolean isLoopback()- See Also:
-
isBroadcast
public boolean isBroadcast()The IPv4 Broadcast (255.255.255.255/32
).See RFC 922, Section 7.
- See Also:
-
isLinkLocal
public boolean isLinkLocal()- See Also:
-
isMulticast
public boolean isMulticast()- See Also:
-
isUniqueLocal
public boolean isUniqueLocal()- See Also:
-
is6to4
public boolean is6to4()- See Also:
-
isTeredo
public boolean isTeredo()- See Also:
-
isDocumentation
public boolean isDocumentation()- See Also:
-
isNetworkBenchmark
public boolean isNetworkBenchmark()- See Also:
-
isOrchid
public boolean isOrchid()- See Also:
-
isCarrierGradeNat
public boolean isCarrierGradeNat()- See Also:
-
getAddressFamily
Deprecated.Please usegetProtocolFamily()
as of Java 1.7. -
getProtocolFamily
-
getAddressType
Gets the type for this address. -
isIPv4
Deprecated.Please usegetProtocolFamily()
-
isIPv6
Deprecated.Please usegetProtocolFamily()
-
getProtocolFamily()
as of Java 1.7.