code: public String encode(String path, Charset charset) {
  
  		int maxBytesPerChar = 10;
  		final StringBuilder rewrittenPath = new StringBuilder(path.length());
  		ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
  		OutputStreamWriter writer = new OutputStreamWriter(buf, charset);
  
  		int c;
  		for (int i = 0; i < path.length(); i++) {
  			c = path.charAt(i);
  			if (safeCharacters.get(c)) {
  				rewrittenPath.append((char) c);
  			} else if (encodeSpaceAsPlus && c == CharUtil.SPACE) {
  				// 对于空格单独处理
  				rewrittenPath.append('+');
  			} else {
  				// convert to external encoding before hex conversion
  				try {
  					writer.write((char) c);
  					writer.flush();
  				} catch (IOException e) {
  					buf.reset();
  					continue;
  				}
  
  				byte[] ba = buf.toByteArray();
  				for (int j = 0; j < ba.length; j++) {
  					// Converting each byte in the buffer
  					byte toEncode = ba[j];
  					rewrittenPath.append('%');
  					HexUtil.appendHex(rewrittenPath, toEncode, false);
  				}
  				buf.reset();
  			}
  		}
  		return rewrittenPath.toString();
  	}
docs: 将URL中的字符串编码为%形式
  
  @param path 需要编码的字符串
  @param charset 编码
  
  @return 编码后的字符串