public Appendable append()

in ch-commons-util/src/main/java/com/cloudhopper/commons/util/codec/URLDecoder.java [86:112]


	public Appendable append(CharSequence in) throws IOException{
		// Ideally, this would share code with URLCodec#decodeUrl(CharSequence, OutputStream),
		// 	but due to operational difference and no common interface between
		// 	ByteBuffer and OutputStream, any attempts to share code result in
		// 	severe performance penalties.
		
		if(in == null) return this;
		for(int i=0, len=in.length(); i<len; i++){
			char c = in.charAt(i);
			if(c == '+'){
				bb.put((byte)' ');
			}else if(c == '%'){
				int x = Character.digit(in.charAt(++i), 16);
				int y = Character.digit(in.charAt(++i), 16);
				if(x == -1 || y == -1){
					throw new IOException("Invalid URL encoding");
				}
				bb.put((byte)((x << 4) + y));
			}else{
				bb.put((byte)c);
			}
			if(!bb.hasRemaining()){
				flush(false);
			}
		}
		return this;
	}