Encode a String using the {@link #PATHSAFE} set of characters.
<p>
Used by URIBuilder to encode path segments.

@param content the string to encode, does not convert space to '+'
@param charset the charset to use
@return the encoded string
495608
static String encPath(final String content, final Charset charset) {
		return urlencode(content, charset, PATHSAFE, false);
	}
894311
public static String pathEncode(String path, Charset charset) {
    return encodeReserved(path, FragmentType.PATH_SEGMENT, charset);

    /*
     * path encoding is not equivalent to query encoding, there are few differences, namely dealing
     * with spaces, !, ', (, ), and ~ characters. we will need to manually process those values.
     */
    // return encoded.replaceAll("\\+", "%20");
  }
484256
public static String encode(String source, String charset) {
		return Base64Encoder.encode(source, charset);
	}
592961
@Nullable
  public static String safeDecodeAsString (@Nullable final byte [] aEncodedBytes, @Nonnull final Charset aCharset)
  {
    ValueEnforcer.notNull (aCharset, "Charset");

    return aEncodedBytes == null ? null : safeDecodeAsString (aEncodedBytes, 0, aEncodedBytes.length, aCharset);
  }
1108919
public static String encodeURIPathComponent(String s) {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      result.append(Char.encodeURIPathComponent(s.charAt(i)));
    }
    return (result.toString());
  }
933072
static String encodeURLString(String stringToEncode) {
        try {
            return java.net.URLEncoder.encode(stringToEncode, "UTF-8").replace("+", ENCODED_SPACE_CHARACTER);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e); // can't happen
        }
    }
965134
public static void setCharsetEncoding(String charset) {
		try {

			String test = "123456890";
			test.getBytes(charset);
			CHARSET_ENCODING = charset;
			encode = true;
		} catch (UnsupportedEncodingException ex) {
			// Reset the encoding to default
			CHARSET_ENCODING = "";
			encode = false;
		}
	}
1020696
public static String encode(String source, String charset) {
		return encode(StrUtil.bytes(source, charset), charset);
	}
366953
public static String unescape(String content) {
		if (StrUtil.isBlank(content)) {
			return content;
		}

		StringBuilder tmp = new StringBuilder(content.length());
		int lastPos = 0, pos = 0;
		char ch;
		while (lastPos < content.length()) {
			pos = content.indexOf("%", lastPos);
			if (pos == lastPos) {
				if (content.charAt(pos + 1) == 'u') {
					ch = (char) Integer.parseInt(content.substring(pos + 2, pos + 6), 16);
					tmp.append(ch);
					lastPos = pos + 6;
				} else {
					ch = (char) Integer.parseInt(content.substring(pos + 1, pos + 3), 16);
					tmp.append(ch);
					lastPos = pos + 3;
				}
			} else {
				if (pos == -1) {
					tmp.append(content.substring(lastPos));
					lastPos = content.length();
				} else {
					tmp.append(content.substring(lastPos, pos));
					lastPos = pos;
				}
			}
		}
		return tmp.toString();
	}
742856
public static CharsetEncoder encoder(Charset charset) {
        checkNotNull(charset, "charset");

        Map<Charset, CharsetEncoder> map = InternalThreadLocalMap.get().charsetEncoderCache();
        CharsetEncoder e = map.get(charset);
        if (e != null) {
            e.reset().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
            return e;
        }

        e = encoder(charset, CodingErrorAction.REPLACE, CodingErrorAction.REPLACE);
        map.put(charset, e);
        return e;
    }
666618
public static InputStream toStream(String content, Charset charset) {
        byte[] bytes = content.getBytes(charset);
        return new ByteArrayInputStream(bytes);
    }
16491
public static String encodeUrlSafe(String source, String charset) {
		return encodeUrlSafe(StrUtil.bytes(source, charset), charset);
	}
1029513
static void encUserInfo(final StringBuilder sb, final String content, final Charset charset) {
        urlEncode(sb, content, charset, USERINFO, false);
    }
507844
private String encode(String value, boolean query) {
    if (this.encode.isEncodingRequired()) {
      return query ? UriUtils.queryEncode(value, this.charset)
          : UriUtils.pathEncode(value, this.charset);
    } else {
      return value;
    }
  }
1301174
private static String encode(String pathElement) {
        try {
            return URLEncoder.encode(pathElement, Charsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
            throw Throwables.propagate(e); // Should never happen
        }
    }
133120
public static String encodeAll(String url, Charset charset) throws UtilException {
		try {
			return java.net.URLEncoder.encode(url, charset.toString());
		} catch (UnsupportedEncodingException e) {
			throw new UtilException(e);
		}
	}
772365
public static String decode(String content) {

		// return content;
		if (content == null || content.length() == 0) {
			return content;
		}
		else {
			byte[] decodeQueryString = org.apache.commons.codec.binary.Base64.decodeBase64(content);
			return new String(decodeQueryString);
		}

	}