public class DnsName extends Object implements CharSequence, Serializable, 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 |
---|---|
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 |
---|---|
String |
asIdn() |
char |
charAt(int index) |
int |
compareTo(DnsName other) |
boolean |
equals(Object other) |
static DnsName |
from(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(String name) |
static DnsName |
from(String[] parts) |
byte[] |
getBytes()
Serialize a domain name under IDN rules.
|
String |
getDomainpart()
Domainpart in ACE representation.
|
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.
|
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(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) |
CharSequence |
subSequence(int start,
int end) |
String |
toString() |
void |
writeToStream(OutputStream os) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
chars, codePoints
public static final int MAX_LABELS
public static final DnsName IN_ADDR_ARPA
public static boolean VALIDATE
public void writeToStream(OutputStream os) throws IOException
IOException
public byte[] getBytes()
public byte[] getRawBytes()
public String getDomainpart()
public String getHostpart()
public int size()
public int length()
length
in interface CharSequence
public char charAt(int index)
charAt
in interface CharSequence
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public String toString()
toString
in interface CharSequence
toString
in class Object
public static DnsName from(CharSequence 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 parse(DataInputStream dis, byte[] data) throws IOException
dis
- The input stream.data
- The raw data (for cross references).IOException
- Should never happen.public int compareTo(DnsName other)
compareTo
in interface Comparable<DnsName>
public boolean isDirectChildOf(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()