UriEncoder { static char[] percentEncode(byte[] bytes) { char[] buf = new char[bytes.length * 3]; int j = 0; for (int i = 0; i < bytes.length; i++) { int b = bytes[i]; buf[j++] = '%'; buf[j++] = hexDigits.charAt((b >> 4) & 0xF); buf[j++] = hexDigits.charAt(b & 0xF); } return buf; }  static String encode(String s); static String encodeAsAscii(String s);  }
@Test public void testPercentEncode() { Assert.assertEquals(new String(UriEncoder.percentEncode(new byte[] { 0x00, 0x7e, 0x7f, (byte)0x80, (byte)0xFF })), "%00%7E%7F%80%FF"); }