public String readDomainName() throws IOException {
        if (pos >= count) {
            throw new EOFException("EOF reading domain name");
        }
        if ((buf[pos] & 0xc0) == 0) {
            String label = readString();
            if (label.length() > 0) {
                String tail = readDomainName();
                if (tail.length() > 0) {
                    label = label + '.' + tail;
                }
            }
            return label;
        } else {
            if ((buf[pos] & 0xc0) != 0xc0) {
                throw new IOException("Invalid domain name compression offset");
            }
            int offset = readShort() & 0x3fff;
            DNSInputStream dnsIn =
                    new DNSInputStream(buf, offset, buf.length - offset);
            return dnsIn.readDomainName();
        }
    }