private static byte []
parseV6(String s) {
	int range = -1;
	byte [] data = new byte[16];

	String [] tokens = s.split(":", -1);

	int first = 0;
	int last = tokens.length - 1;

	if (tokens[0].length() == 0) {
		// If the first two tokens are empty, it means the string
		// started with ::, which is fine.  If only the first is
		// empty, the string started with :, which is bad.
		if (last - first > 0 && tokens[1].length() == 0)
			first++;
		else
			return null;
	}

	if (tokens[last].length() == 0) {
		// If the last two tokens are empty, it means the string
		// ended with ::, which is fine.  If only the last is
		// empty, the string ended with :, which is bad.
		if (last - first > 0 && tokens[last - 1].length() == 0)
			last--;
		else
			return null;
	}

	if (last - first + 1 > 8)
		return null;

	int i, j;
	for (i = first, j = 0; i <= last; i++) {
		if (tokens[i].length() == 0) {
			if (range >= 0)
				return null;
			range = j;
			continue;
		}

		if (tokens[i].indexOf('.') >= 0) {
			// An IPv4 address must be the last component
			if (i < last)
				return null;
			// There can't have been more than 6 components.
			if (i > 6)
				return null;
			byte [] v4addr = Address.toByteArray(tokens[i], IPv4);
			if (v4addr == null)
				return null;
			for (int k = 0; k < 4; k++)
				data[j++] = v4addr[k];
			break;
		}

		try {
			for (int k = 0; k < tokens[i].length(); k++) {
				char c = tokens[i].charAt(k);
				if (Character.digit(c, 16) < 0)
					return null;
			}
			int x = Integer.parseInt(tokens[i], 16);
			if (x > 0xFFFF || x < 0)
				return null;
			data[j++] = (byte)(x >>> 8);
			data[j++] = (byte)(x & 0xFF);
		}
		catch (NumberFormatException e) {
			return null;
		}
	}

	if (j < 16 && range < 0)
		return null;

	if (range >= 0) {
		int empty = 16 - j;
		System.arraycopy(data, range, data, range + empty, j - range);
		for (i = range; i < range + empty; i++)
			data[i] = 0;
	}

	return data;
}
Routines dealing with IP addresses.  Includes functions similar to
those in the java.net.InetAddress class.

@author Brian Wellington
src/main/java/core/org/xbill/DNS/Address.java