Class DnsName
- java.lang.Object
-
- org.minidns.dnsname.DnsName
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,java.lang.Comparable<DnsName>
public final class DnsName extends java.lang.Object implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<DnsName>
A DNS name, also called "domain name". A DNS name consists of multiple 'labels' and is subject to certain restrictions (see for example RFC 3696 ยง 2.).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
More information about Internationalized Domain Names can be found at: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 usegetRawAce()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 usingasIdn().- See Also:
- RFC 3696, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringaceThe DNS name in ASCII Compatible Encoding (ACE).static DnsNameIN_ADDR_ARPAstatic DnsNameIP6_ARPAstatic intMAX_LABELSstatic DnsNameROOTstatic booleanVALIDATEWhether or not the DNS name is validated on construction.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringasIdn()charcharAt(int index)intcompareTo(DnsName other)booleanequals(java.lang.Object other)static DnsNamefrom(java.lang.CharSequence name)static DnsNamefrom(java.lang.CharSequence child, DnsName parent)static DnsNamefrom(java.lang.String name)static DnsNamefrom(java.lang.String[] parts)static DnsNamefrom(DnsLabel grandchild, DnsLabel child, DnsName parent)static DnsNamefrom(DnsLabel child, DnsName parent)static DnsNamefrom(DnsName... nameComponents)static DnsNamefrom(DnsName child, DnsName parent)Create a DNS name by "concatenating" the child under the parent name.byte[]getBytes()Serialize a domain name under IDN rules.java.lang.StringgetDomainpart()Domainpart in ACE representation.java.lang.StringgetHostpart()Hostpart in ACE representation.DnsLabelgetHostpartLabel()DnsLabelgetLabel(int labelNum)intgetLabelCount()DnsLabel[]getLabels()Get a copy of the labels of this DNS name.DnsNamegetParent()Return the parent of this DNS label.java.lang.StringgetRawAce()byte[]getRawBytes()DnsLabel[]getRawLabels()Get a copy of the raw labels of this DNS name.inthashCode()booleanisChildOf(DnsName parent)booleanisDirectChildOf(DnsName parent)booleanisRootLabel()intlength()static DnsNameparse(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).intsize()DnsNamestripToLabels(int labelCount)java.lang.CharSequencesubSequence(int start, int end)java.lang.StringtoString()voidwriteToStream(java.io.OutputStream os)
-
-
-
Field Detail
-
MAX_LABELS
public static final int MAX_LABELS
- See Also:
- Constant Field Values
-
IN_ADDR_ARPA
public static final DnsName IN_ADDR_ARPA
-
VALIDATE
public static boolean VALIDATE
Whether or not the DNS name is validated on construction.
-
ace
public final java.lang.String ace
The DNS name in ASCII Compatible Encoding (ACE).
-
-
Method Detail
-
writeToStream
public void writeToStream(java.io.OutputStream os) throws java.io.IOException
- Throws:
java.io.IOException
-
getBytes
public byte[] getBytes()
Serialize a domain name under IDN rules.- Returns:
- The binary domain name representation.
-
getRawBytes
public byte[] getRawBytes()
-
getRawAce
public java.lang.String getRawAce()
-
asIdn
public java.lang.String asIdn()
-
getDomainpart
public java.lang.String getDomainpart()
Domainpart in ACE representation.- Returns:
- the domainpart in ACE representation.
-
getHostpart
public java.lang.String getHostpart()
Hostpart in ACE representation.- Returns:
- the hostpart in ACE representation.
-
getHostpartLabel
public DnsLabel getHostpartLabel()
-
size
public int size()
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
- Specified by:
subSequencein interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
from
public static DnsName from(DnsName child, DnsName parent)
Create a DNS name by "concatenating" the child under the parent name. The child can also be seen as the "left" part of the resulting DNS name and the parent is the "right" part.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".
- Parameters:
child- the child DNS name.parent- the parent DNS name.- Returns:
- the resulting of DNS name.
-
parse
public static DnsName parse(java.io.DataInputStream dis, byte[] data) throws java.io.IOException
Parse a domain name starting at the current offset and moving the input stream pointer past this domain name (even if cross references occure).- Parameters:
dis- The input stream.data- The raw data (for cross references).- Returns:
- The domain name string.
- Throws:
java.io.IOException- Should never happen.
-
compareTo
public int compareTo(DnsName other)
- Specified by:
compareToin interfacejava.lang.Comparable<DnsName>
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isDirectChildOf
public boolean isDirectChildOf(DnsName parent)
-
getLabelCount
public int getLabelCount()
-
getLabels
public DnsLabel[] getLabels()
Get a copy of the labels of this DNS name. The resulting array will contain the labels in reverse order, that is, the top-level domain will be at res[0].- Returns:
- an array of the labels in reverse order.
-
getRawLabels
public DnsLabel[] getRawLabels()
Get a copy of the raw labels of this DNS name. The resulting array will contain the labels in reverse order, that is, the top-level domain will be at res[0].- Returns:
- an array of the raw labels in reverse order.
-
stripToLabels
public DnsName stripToLabels(int labelCount)
-
getParent
public DnsName getParent()
Return the parent of this DNS label. Will return the root label if this label itself is the root label (because there is no parent of root).For example:
"foo.bar.org".getParent() == "bar.org"".".getParent() == "."
- Returns:
- the parent of this DNS label.
-
isRootLabel
public boolean isRootLabel()
-
-