Using the Java code from GNU libidn. The rules for Punycode are laid out in RFC 3492. The Wikipedia Punycode entry is a bit easier to read.