code: protected static char[] encode(String original, BitSet allowed,
              String charset) throws URIException {
          if (original == null) {
              throw new IllegalArgumentException("Original string may not be null");
          }
          if (allowed == null) {
              throw new IllegalArgumentException("Allowed bitset may not be null");
          }
          byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(original, charset));
          return EncodingUtil.getAsciiString(rawdata).toCharArray();
      }
docs: Encodes URI string.
  
  This is a two mapping, one from original characters to octets, and
  subsequently a second from octets to URI characters:
  <p><blockquote><pre>
  original character sequence-&gt;octet sequence-&gt;URI character sequence
  </pre></blockquote><p>
  
  An escaped octet is encoded as a character triplet, consisting of the
  percent character "%" followed by the two hexadecimal digits
  representing the octet code. For example, "%20" is the escaped
  encoding for the US-ASCII space character.
  <p>
  Conversion from the local filesystem character set to UTF-8 will
  normally involve a two step process. First convert the local character
  set to the UCS; then convert the UCS to UTF-8.
  The first step in the process can be performed by maintaining a mapping
  table that includes the local character set code and the corresponding
  UCS code.
  The next step is to convert the UCS character code to the UTF-8 encoding.
  <p>
  Mapping between vendor codepages can be done in a very similar manner
  as described above.
  <p>
  The only time escape encodings can allowedly be made is when a URI is
  being created from its component parts.  The escape and validate methods
  are internally performed within this method.
  
  @param original the original character sequence
  @param allowed those characters that are allowed within a component
  @param charset the protocol charset
  @return URI character sequence
  @throws URIException null component or unsupported character encoding