in ch-commons-util/src/main/java/com/cloudhopper/commons/util/codec/URLCodec.java [150:174]
public static void decode(CharSequence in, OutputStream out) throws IOException{
CharBuffer cb;
if(in instanceof CharBuffer){
cb = (CharBuffer)in;
}else if(in != null){
cb = CharBuffer.wrap(in);
}else{
return;
}
while(cb.hasRemaining()){
char c = cb.get();
if(c == '+'){
out.write(' ');
}else if(c == '%'){
int x = Character.digit(cb.get(), 16);
int y = Character.digit(cb.get(), 16);
if(x == -1 || y == -1){
throw new IOException("Invalid URL encoding");
}
out.write((x << 4) + y);
}else{
out.write(c);
}
}
}