docs: public static String encode(String s) {
          if (s == null) {
              return null;
          }
  
          StringBuilder builder = null;
          int begin = 0;
  
          for (int i = 0, length = s.length(); i < length; i++) {
              char ch = s.charAt(i);
  
              // RFC 2396, Section 3.3.  See also:
              // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5063160
              switch (ch) {
                  // lowalpha
                  case 'a':
                  case 'b':
                  case 'c':
                  case 'd':
                  case 'e':
                  case 'f':
                  case 'g':
                  case 'h':
                  case 'i':
                  case 'j':
                  case 'k':
                  case 'l':
                  case 'm':
                  case 'n':
                  case 'o':
                  case 'p':
                  case 'q':
                  case 'r':
                  case 's':
                  case 't':
                  case 'u':
                  case 'v':
                  case 'w':
                  case 'x':
                  case 'y':
                  case 'z':
                      // upalpha
                  case 'A':
                  case 'B':
                  case 'C':
                  case 'D':
                  case 'E':
                  case 'F':
                  case 'G':
                  case 'H':
                  case 'I':
                  case 'J':
                  case 'K':
                  case 'L':
                  case 'M':
                  case 'N':
                  case 'O':
                  case 'P':
                  case 'Q':
                  case 'R':
                  case 'S':
                  case 'T':
                  case 'U':
                  case 'V':
                  case 'W':
                  case 'X':
                  case 'Y':
                  case 'Z':
                      // digit
                  case '0':
                  case '1':
                  case '2':
                  case '3':
                  case '4':
                  case '5':
                  case '6':
                  case '7':
                  case '8':
                  case '9':
                      // mark
                  case '-':
                  case '_':
                  case '.':
                  case '!':
                  case '~':
                  case '*':
                  case '\'':
                  case '(':
                  case ')':
                      // path_segments
                  case '/':
                      // segment
                  case ';':
                      // pchar
                  case ':':
                  case '@':
                  case '&':
                  case '=':
                  case '+':
                  case '$':
                  case ',':
                      break;
  
                  default:
                      if (builder == null) {
                          builder = new StringBuilder();
                      }
  
                      builder.append(s, begin, i);
                      begin = i + 1;
  
                      // Reserved characters are encoded in java.io.DataInput's
                      // "modified UTF-8" format.
                      if (ch <= 0x7f) {
                          appendURLEscapeEncoding(builder, ch);
                      } else if (ch <= 0x7ff) {
                          appendURLEscapeEncoding(builder, 0xc0 | (ch >> 6));
                          appendURLEscapeEncoding(builder, 0x80 | (ch & 0x3f));
                      } else {
                          appendURLEscapeEncoding(builder, 0xe0 | (ch >> 12));
                          appendURLEscapeEncoding(builder, 0x80 | ((ch >> 6) & 0x3f));
                          appendURLEscapeEncoding(builder, 0x80 | (ch & 0x3f));
                      }
                      break;
              }
          }
  
          if (builder != null) {
              return builder.append(s, begin, s.length()).toString();
          }
  
          return s;
      }