예제 #1
0
 public synchronized String encode(byte[] input, int start, int end) {
   mBuilder.clear();
   for (int i = start; i < end; i++) {
     byte atom = input[i];
     if (isConvert(atom)) {
       encodeAtPersent(atom);
     } else {
       mBuilder.append(atom);
     }
   }
   return new String(mBuilder.getBuffer(), 0, mBuilder.length());
 }
예제 #2
0
  public synchronized byte[] decode(byte[] input) throws IOException {
    mBuilder.clear();

    int len = input.length;
    for (int i = 0; i < len; ) {
      byte atom = input[i];
      if (atom != '%') {
        mBuilder.append(atom);
        i += 1;
      } else {
        mBuilder.append(convertChar2Byte(input, i));
        i += 3;
      }
    }

    byte[] output = new byte[mBuilder.length()];
    System.arraycopy(mBuilder.getBuffer(), 0, output, 0, output.length);
    return output;
  }