public Name
fromDNAME(DNAMERecord dname) throws NameTooLongException {
	Name dnameowner = dname.getName();
	Name dnametarget = dname.getTarget();
	if (!subdomain(dnameowner))
		return null;

	int plabels = labels() - dnameowner.labels();
	int plength = length() - dnameowner.length();
	int pstart = offset(0);

	int dlabels = dnametarget.labels();
	int dlength = dnametarget.length();

	if (plength + dlength > MAXNAME)
		throw new NameTooLongException();

	Name newname = new Name();
	newname.setlabels(plabels + dlabels);
	newname.name = new byte[plength + dlength];
	System.arraycopy(name, pstart, newname.name, 0, plength);
	System.arraycopy(dnametarget.name, 0, newname.name, plength, dlength);

	for (int i = 0, pos = 0; i < MAXOFFSETS && i < plabels + dlabels; i++) {
		newname.setoffset(i, pos);
		pos += (newname.name[pos] + 1);
	}
	return newname;
}
Generates a new Name to be used when following a DNAME.
@param dname The DNAME record to follow.
@return The constructed name.
@throws NameTooLongException The resulting name is too long.
src/main/java/core/org/xbill/DNS/Name.java