code: private static ByteBuffer decodePercentEncodedOctets(String s, int i, ByteBuffer bb) {
          if (bb == null) {
              bb = ByteBuffer.allocate(1);
          } else {
              bb.clear();
          }
  
          while (true) {
              // Decode the hex digits
              bb.put((byte) (decodeHex(s, i++) << 4 | decodeHex(s, i++)));
  
              // Finish if at the end of the string
              if (i == s.length()) {
                  break;
              }
  
              // Finish if no more percent-encoded octets follow
              if (s.charAt(i++) != '%') {
                  break;
              }
  
              // Check if the byte buffer needs to be increased in size
              if (bb.position() == bb.capacity()) {
                  bb.flip();
                  // Create a new byte buffer with the maximum number of possible
                  // octets, hence resize should only occur once
                  ByteBuffer bb_new = ByteBuffer.allocate(s.length() / 3);
                  bb_new.put(bb);
                  bb = bb_new;
              }
          }
  
          bb.flip();
          return bb;
      }
docs: Decode a continuous sequence of percent encoded octets.
  <p>
  Assumes the index, i, starts that the first hex digit of the first
  percent-encoded octet.