Exemplo n.º 1
0
 /**
  * ** Hex-encodes a URL argument ** @param sb The StringBuffer where the hex encoded String
  * argument will be placed ** @param s The URL argument to encode ** @param obfuscateAll True to
  * force hex-encoding on all argument characters ** @return The StringBuffer where the hex-encoded
  * String will be placed
  */
 public static StringBuffer encodeArg(StringBuffer sb, String s, boolean obfuscateAll) {
   if (sb == null) {
     sb = new StringBuffer();
   }
   if (s != null) {
     char ch[] = new char[s.length()];
     s.getChars(0, s.length(), ch, 0);
     for (int i = 0; i < ch.length; i++) {
       if (obfuscateAll || URIArg.shouldEncodeArgChar(ch[i])) {
         // escape non-alphanumeric characters
         sb.append("%");
         sb.append(Integer.toHexString(0x100 + (ch[i] & 0xFF)).substring(1));
       } else {
         // letters and digits are ok as-is
         sb.append(ch[i]);
       }
     }
   }
   return sb;
 }