Encode a Uri Chunk, ensuring that all reserved characters are also encoded.

@param value to encode.
@param type identifying which uri fragment rules to apply.
@param charset to use.
@return an encoded uri chunk.
497456
private static String encodeChunk(String value, FragmentType type, Charset charset) {
    byte[] data = value.getBytes(charset);
    ByteArrayOutputStream encoded = new ByteArrayOutputStream();

    for (byte b : data) {
      if (type.isAllowed(b)) {
        encoded.write(b);
      } else {
        /* percent encode the byte */
        pctEncode(b, encoded);
      }
    }
    return new String(encoded.toByteArray());
  }
16491
public static String encodeUrlSafe(String source, String charset) {
		return encodeUrlSafe(StrUtil.bytes(source, charset), charset);
	}
1163943
public static String encodeQuery(String url, Charset charset) {
		if (StrUtil.isEmpty(url)) {
			return url;
		}
		if (null == charset) {
			charset = CharsetUtil.defaultCharset();
		}
		return URLEncoder.QUERY.encode(url, charset);
	}
253261
public static String base64Encode(final String value) {
        validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
        return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));
    }
789100
public static function encodeToBase64($value, string $type = null): string
    {
        return \base64_encode(
            self::run(self::ENCODER, $value, $type)
        );
    }
28293
public static String encodePath(String path, String encoding) throws UnsupportedEncodingException {
		return HierarchicalUriComponents.encodeUriComponent(path, encoding, HierarchicalUriComponents.Type.PATH);
	}
1574
protected TypeValuePairType getTypeValuePair(String type, byte[] value) {
        TypeValuePairType tvp = new TypeValuePairType();
        tvp.setType(type);
        //tvp.setValue(Base64.encodeBase64Chunked(value));
        // the TVP itself base64 encodes now, no need for this
        tvp.setValue(value);
        return tvp;
    }
872025
public static String encodeUrlSafe(byte[] source, String charset) {
		return StrUtil.str(encodeUrlSafe(source, false), charset);
	}
795729
public static String urlDecode(final String value) {
        if (value == null) {
            return null;
        }

        try {
            return URLDecoder.decode(value, DEFAULT_ENCODING);

        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex);
        }
    }
1273727
@SuppressWarnings({"unchecked", "rawtypes"})
    public U encode(Object value) {
        requireNonNull(value, "Value for encoding can not be null");

        TypeEncoder encoder = classMapping.get(value.getClass());
        if (encoder != null)
            return (U) encoder.encode(value);

        throw new TypeEncodingException("An unknown type [" + value.getClass() + "] was encountered");
    }
1106208
static void encPath(final StringBuilder sb, final String content, final Charset charset) {
        urlEncode(sb, content, charset, PATHSAFE, false);
    }
802685
public static String encode(String value) {
        byte[] val = value.getBytes(UTF_8);
        return delegate.encode(val);
    }
1275122
@Override
    public String getCharsetFromContentType(String type) {
        if (null != type) {
            int index = type.indexOf(';');
            if (-1 != index) {
                index = type.indexOf("charset=", (index + 1));
                if (-1 != index) {
                    String charset = type.substring(index + 8).trim();
                    int end = charset.length() - 1;
                    if (-1 == end) {
                        // empty value following charset=
                        return null;
                    }
                    if (end > 0 && '"' == charset.charAt(0) && '"' == charset.charAt(end)) {
                        // strip off quotes if both exist
                        charset = charset.substring(1, end);
                    }
                    return charset;
                }
            }
        }
        return null;
    }
1249448
public String getEncodingByMimeType(String type)
    {
        String encoding =null;

        if (type!=null)
            encoding=(String)_encodingMap.get(type);

        return encoding;
    }
181002
private String encodeUri( String uri )
	{
		StringBuilder newUri = new StringBuilder();
		StringTokenizer st = new StringTokenizer( uri, "/ ", true );
		while ( st.hasMoreTokens())
		{
			String tok = st.nextToken();
			if ( tok.equals( "/" )) {
				newUri.append('/');
			} else if ( tok.equals( " " )) {
				newUri.append("%20");
			} else {
				try {
					newUri.append(URLEncoder.encode( tok, "UTF-8" ));
				} catch ( UnsupportedEncodingException uee ) { // NOPMD - imported code
					// imported code
				}
			}
		}
		return newUri.toString();
	}
88129
public static String urlEncode(String src) throws UnsupportedEncodingException {
		return URLEncoder.encode(src, Charsets.UTF_8.name()).replace("+", "%20");
	}
908866
public Object decode(String alias, U value) {
        requireNonNull(alias, "Not allowed to have a null alias");
        requireNonNull(value, "Value for decoding can not be null");

        TypeEncoder<?, U> encoder = aliasMapping.get(alias);
        if (encoder != null)
            return encoder.decode(value);

        throw new TypeDecodingException("An unknown alias [" + alias + "] was encountered");
    }