src/main/java/de/qaware/xff/util/uri/HierarchicalUriComponents.java
/**
	 * Encode the given source into an encoded String using the rules specified
	 * by the given component and with the given options.
	 *
	 * @param source  the source String
	 * @param charset the encoding of the source String
	 * @param type    the URI component for the source
	 * @return the encoded URI
	 * @throws IllegalArgumentException when the given value is not a valid URI component
	 */
Encode the given source into an encoded String using the rules specified
by the given component and with the given options.


Encode the given source into an encoded String using the rules specified by the given component and with the given options .
@SuppressWarnings("squid:S109")
	static String encodeUriComponent(String source, Charset charset, URIComponentType type) {
		if (StringUtils.isEmpty(source)) {
			return source;
		}
		Validate.notNull(charset, "Charset must not be null");
		Validate.notNull(type, "URIComponentType must not be null");
		byte[] bytes = source.getBytes(charset);
		ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);
		boolean changed = false;
		for (byte b : bytes) {
			if (b < 0) {
				b += 256;
			}
			if (type.isAllowedCharacter(b)) {
				bos.write(b);
			} else {
				bos.write('%');
				char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
				char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
				bos.write(hex1);
				bos.write(hex2);
				changed = true;
			}
		}
		return (changed ? bufferToString(charset, bos) : source);
	}
@ SuppressWarnings ( "squid:S109" ) static String encodeUriComponent ( String source , Charset charset , URIComponentType type ) { if ( StringUtils . isEmpty ( source ) ) { return source ; } Validate . notNull ( charset , "Charset must not be null" ) ; Validate . notNull ( type , "URIComponentType must not be null" ) ; byte [ ] bytes = source . getBytes ( charset ) ; ByteArrayOutputStream bos = new ByteArrayOutputStream ( bytes . length ) ; boolean changed = false ; for ( byte b : bytes ) { if ( b < 0 ) { b += 256 ; } if ( type . isAllowedCharacter ( b ) ) { bos . write ( b ) ; } else { bos . write ( '%' ) ; char hex1 = Character . toUpperCase ( Character . forDigit ( ( b >> 4 ) & 0xF , 16 ) ) ; char hex2 = Character . toUpperCase ( Character . forDigit ( b & 0xF , 16 ) ) ; bos . write ( hex1 ) ; bos . write ( hex2 ) ; changed = true ; } } return ( changed ? bufferToString ( charset , bos ) : source ) ; }
Encode the given source into an encoded String using the rules specified
 by the given component and with the given options.
Encode the given source into an encoded String using the rules specified by the given component and with the given options .
//"magic number"  required for encoder logic //split byte into two 4 bit nibbles and convert them to characters