public class DnsName extends java.lang.Object implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<DnsName>
Instances of this class can be created by using from(String).
This class holds three representations of a DNS name: ACE, raw ACE and IDN. ACE (ASCII Compatible Encoding), which
can be accessed via ace, represents mostly the data that got send over the wire. But since DNS names are
case insensitive, the ACE value is normalized to lower case. You can use getRawAce() to get the raw ACE data
that was received, which possibly includes upper case characters. The IDN (Internationalized Domain Name), that is
the DNS name as it should be shown to the user, can be retrieved using asIdn().
| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
ace
The DNS name in ASCII Compatible Encoding (ACE).
|
static DnsName |
IN_ADDR_ARPA |
static DnsName |
IP6_ARPA |
static int |
MAX_LABELS |
static DnsName |
ROOT |
static boolean |
VALIDATE
Whether or not the DNS name is validated on construction.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
asIdn() |
char |
charAt(int index) |
int |
compareTo(DnsName other) |
boolean |
equals(java.lang.Object other) |
static DnsName |
from(java.lang.CharSequence name) |
static DnsName |
from(DnsName... nameComponents) |
static DnsName |
from(DnsName child,
DnsName parent)
Create a DNS name by "concatenating" the child under the parent name.
|
static DnsName |
from(java.lang.String name) |
static DnsName |
from(java.lang.String[] parts) |
byte[] |
getBytes()
Serialize a domain name under IDN rules.
|
java.lang.String |
getDomainpart()
Domainpart in ACE representation.
|
java.lang.String |
getHostpart()
Hostpart in ACE representation.
|
int |
getLabelCount() |
DnsLabel[] |
getLabels()
Get a copy of the labels of this DNS name.
|
DnsName |
getParent()
Return the parent of this DNS label.
|
java.lang.String |
getRawAce() |
byte[] |
getRawBytes() |
DnsLabel[] |
getRawLabels()
Get a copy of the raw labels of this DNS name.
|
int |
hashCode() |
boolean |
isChildOf(DnsName parent) |
boolean |
isDirectChildOf(DnsName parent) |
boolean |
isRootLabel() |
int |
length() |
static DnsName |
parse(java.io.DataInputStream dis,
byte[] data)
Parse a domain name starting at the current offset and moving the input
stream pointer past this domain name (even if cross references occure).
|
int |
size() |
DnsName |
stripToLabels(int labelCount) |
java.lang.CharSequence |
subSequence(int start,
int end) |
java.lang.String |
toString() |
void |
writeToStream(java.io.OutputStream os) |
public static final int MAX_LABELS
public static final DnsName ROOT
public static final DnsName IN_ADDR_ARPA
public static final DnsName IP6_ARPA
public static boolean VALIDATE
public final java.lang.String ace
public void writeToStream(java.io.OutputStream os)
throws java.io.IOException
java.io.IOExceptionpublic byte[] getBytes()
public byte[] getRawBytes()
public java.lang.String getRawAce()
public java.lang.String asIdn()
public java.lang.String getDomainpart()
public java.lang.String getHostpart()
public int size()
public int length()
length in interface java.lang.CharSequencepublic char charAt(int index)
charAt in interface java.lang.CharSequencepublic java.lang.CharSequence subSequence(int start,
int end)
subSequence in interface java.lang.CharSequencepublic java.lang.String toString()
toString in interface java.lang.CharSequencetoString in class java.lang.Objectpublic static DnsName from(java.lang.CharSequence name)
public static DnsName from(java.lang.String name)
public static DnsName from(DnsName child, DnsName parent)
For example using "i.am.the.child" as child and "of.this.parent.example" as parent, will result in a DNS name: "i.am.the.child.of.this.parent.example".
child - the child DNS name.parent - the parent DNS name.public static DnsName from(java.lang.String[] parts)
public static DnsName parse(java.io.DataInputStream dis, byte[] data) throws java.io.IOException
dis - The input stream.data - The raw data (for cross references).java.io.IOException - Should never happen.public int compareTo(DnsName other)
compareTo in interface java.lang.Comparable<DnsName>public boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean isDirectChildOf(DnsName parent)
public boolean isChildOf(DnsName parent)
public int getLabelCount()
public DnsLabel[] getLabels()
public DnsLabel[] getRawLabels()
public DnsName stripToLabels(int labelCount)
public DnsName getParent()
For example:
"foo.bar.org".getParent() == "bar.org" ".".getParent() == "."public boolean isRootLabel()