private static String encode ( String value , BitSet unescapedChars ) { // Code from org.apache.commons.codec.net.URLCodec.encodeUrl(BitSet, byte[]) final ByteArrayOutputStream buffer = new ByteArrayOutputStream ( ) ; for ( final byte c : value . getBytes ( CHARSET ) ) { int b = c ; if ( b < 0 ) { b = 256 + b ; } if ( unescapedChars . get ( b ) ) { buffer . write ( b ) ; } else { buffer . write ( ESCAPE_CHAR ) ; final char hex1 = Character . toUpperCase ( Character . forDigit ( ( b >> 4 ) & 0xF , HEXADECIMAL_RADIX ) ) ; final char hex2 = Character . toUpperCase ( Character . forDigit ( b & 0xF , HEXADECIMAL_RADIX ) ) ; buffer . write ( hex1 ) ; buffer . write ( hex2 ) ; } } return new String ( buffer . toByteArray ( ) , CHARSET ) ; }
URL - encode a String .