@Test public void getLabelsTest() { final String tldLabelString = "tld"; final String secondLevelString = "second-level-domain"; final String thirdLevelString = "third-level-domain"; final String dnsNameString = thirdLevelString + '.' + secondLevelString + '.' + tldLabelString; final DnsName dnsName = DnsName.from(dnsNameString); DnsLabel[] labels = dnsName.getLabels(); assertEquals(tldLabelString, labels[0].label); assertEquals(secondLevelString, labels[1].label); assertEquals(thirdLevelString, labels[2].label); }
private static DnsLabel[] getLabels(String ace) { String[] labels = ace.split(LABEL_SEP_REGEX, MAX_LABELS); for (int i = 0; i < labels.length / 2; i++) { String t = labels[i]; int j = labels.length - i - 1; labels[i] = labels[j]; labels[j] = t; } try { return DnsLabel.from(labels); } catch (DnsLabel.LabelToLongException e) { throw new InvalidDnsNameException.LabelTooLongException(ace, e.label); } }
DnsName implements CharSequence, Serializable, Comparable<DnsName> { private static DnsLabel[] getLabels(String ace) { String[] labels = ace.split(LABEL_SEP_REGEX, MAX_LABELS); for (int i = 0; i < labels.length / 2; i++) { String t = labels[i]; int j = labels.length - i - 1; labels[i] = labels[j]; labels[j] = t; } try { return DnsLabel.from(labels); } catch (DnsLabel.LabelToLongException e) { throw new InvalidDnsNameException.LabelTooLongException(ace, e.label); } } }
DnsName implements CharSequence, Serializable, Comparable<DnsName> { private static DnsLabel[] getLabels(String ace) { String[] labels = ace.split(LABEL_SEP_REGEX, MAX_LABELS); for (int i = 0; i < labels.length / 2; i++) { String t = labels[i]; int j = labels.length - i - 1; labels[i] = labels[j]; labels[j] = t; } try { return DnsLabel.from(labels); } catch (DnsLabel.LabelToLongException e) { throw new InvalidDnsNameException.LabelTooLongException(ace, e.label); } } private  DnsName(String name); private  DnsName(String name, boolean inAce); private  DnsName(DnsLabel[] rawLabels, boolean validateMaxDnsnameLength); }
DnsName implements CharSequence, Serializable, Comparable<DnsName> { private static DnsLabel[] getLabels(String ace) { String[] labels = ace.split(LABEL_SEP_REGEX, MAX_LABELS); for (int i = 0; i < labels.length / 2; i++) { String t = labels[i]; int j = labels.length - i - 1; labels[i] = labels[j]; labels[j] = t; } try { return DnsLabel.from(labels); } catch (DnsLabel.LabelToLongException e) { throw new InvalidDnsNameException.LabelTooLongException(ace, e.label); } } private  DnsName(String name); private  DnsName(String name, boolean inAce); private  DnsName(DnsLabel[] rawLabels, boolean validateMaxDnsnameLength); void writeToStream(OutputStream os); byte[] getBytes(); byte[] getRawBytes(); String getRawAce(); String asIdn(); String getDomainpart(); String getHostpart(); DnsLabel getHostpartLabel(); int size(); @Override int length(); @Override char charAt(int index); @Override CharSequence subSequence(int start, int end); @Override String toString(); static DnsName from(CharSequence name); static DnsName from(String name); static DnsName from(DnsName child, DnsName parent); static DnsName from(DnsLabel child, DnsName parent); static DnsName from(DnsLabel grandchild, DnsLabel child, DnsName parent); static DnsName from(DnsName... nameComponents); static DnsName from(String[] parts); static DnsName parse(DataInputStream dis, byte[] data); @Override int compareTo(DnsName other); @Override boolean equals(Object other); @Override int hashCode(); boolean isDirectChildOf(DnsName parent); boolean isChildOf(DnsName parent); int getLabelCount(); DnsLabel[] getLabels(); DnsLabel getLabel(int labelNum); DnsLabel[] getRawLabels(); DnsName stripToLabels(int labelCount); DnsName getParent(); boolean isRootLabel(); }
DnsName implements CharSequence, Serializable, Comparable<DnsName> { private static DnsLabel[] getLabels(String ace) { String[] labels = ace.split(LABEL_SEP_REGEX, MAX_LABELS); for (int i = 0; i < labels.length / 2; i++) { String t = labels[i]; int j = labels.length - i - 1; labels[i] = labels[j]; labels[j] = t; } try { return DnsLabel.from(labels); } catch (DnsLabel.LabelToLongException e) { throw new InvalidDnsNameException.LabelTooLongException(ace, e.label); } } private  DnsName(String name); private  DnsName(String name, boolean inAce); private  DnsName(DnsLabel[] rawLabels, boolean validateMaxDnsnameLength); void writeToStream(OutputStream os); byte[] getBytes(); byte[] getRawBytes(); String getRawAce(); String asIdn(); String getDomainpart(); String getHostpart(); DnsLabel getHostpartLabel(); int size(); @Override int length(); @Override char charAt(int index); @Override CharSequence subSequence(int start, int end); @Override String toString(); static DnsName from(CharSequence name); static DnsName from(String name); static DnsName from(DnsName child, DnsName parent); static DnsName from(DnsLabel child, DnsName parent); static DnsName from(DnsLabel grandchild, DnsLabel child, DnsName parent); static DnsName from(DnsName... nameComponents); static DnsName from(String[] parts); static DnsName parse(DataInputStream dis, byte[] data); @Override int compareTo(DnsName other); @Override boolean equals(Object other); @Override int hashCode(); boolean isDirectChildOf(DnsName parent); boolean isChildOf(DnsName parent); int getLabelCount(); DnsLabel[] getLabels(); DnsLabel getLabel(int labelNum); DnsLabel[] getRawLabels(); DnsName stripToLabels(int labelCount); DnsName getParent(); boolean isRootLabel(); static final int MAX_LABELS; static final DnsName ROOT; static final DnsName IN_ADDR_ARPA; static final DnsName IP6_ARPA; static boolean VALIDATE; final String ace; }