Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding. This codec is meant to be a replacement for standard Java classes java.net.URLEncoder and java.net.URLDecoder on older Java platforms, as these classes in Java versions below 1.4 rely o
| 45 | * @since 1.2 |
| 46 | */ |
| 47 | public class URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { |
| 48 | |
| 49 | /** |
| 50 | * The default charset used for string decoding and encoding. |
| 51 | * |
| 52 | * @deprecated TODO: This field will be changed to a private final Charset in 2.0. (CODEC-126) |
| 53 | */ |
| 54 | @Deprecated |
| 55 | protected volatile String charset; // added volatile: see CODEC-232 |
| 56 | |
| 57 | /** |
| 58 | * Release 1.5 made this field final. |
| 59 | */ |
| 60 | protected static final byte ESCAPE_CHAR = '%'; |
| 61 | |
| 62 | /** |
| 63 | * BitSet of www-form-url safe characters. |
| 64 | * This is a copy of the internal BitSet which is now used for the conversion. |
| 65 | * Changes to this field are ignored. |
| 66 | * @deprecated 1.11 Will be removed in 2.0 (CODEC-230) |
| 67 | */ |
| 68 | @Deprecated |
| 69 | protected static final BitSet WWW_FORM_URL; |
| 70 | |
| 71 | private static final BitSet WWW_FORM_URL_SAFE = new BitSet(256); |
| 72 | |
| 73 | // Static initializer for www_form_url |
| 74 | static { |
| 75 | // alpha characters |
| 76 | for (int i = 'a'; i <= 'z'; i++) { |
| 77 | WWW_FORM_URL_SAFE.set(i); |
| 78 | } |
| 79 | for (int i = 'A'; i <= 'Z'; i++) { |
| 80 | WWW_FORM_URL_SAFE.set(i); |
| 81 | } |
| 82 | // numeric characters |
| 83 | for (int i = '0'; i <= '9'; i++) { |
| 84 | WWW_FORM_URL_SAFE.set(i); |
| 85 | } |
| 86 | // special chars |
| 87 | WWW_FORM_URL_SAFE.set('-'); |
| 88 | WWW_FORM_URL_SAFE.set('_'); |
| 89 | WWW_FORM_URL_SAFE.set('.'); |
| 90 | WWW_FORM_URL_SAFE.set('*'); |
| 91 | // blank to be replaced with + |
| 92 | WWW_FORM_URL_SAFE.set(' '); |
| 93 | |
| 94 | // Create a copy in case anyone (ab)uses it |
| 95 | WWW_FORM_URL = (BitSet) WWW_FORM_URL_SAFE.clone(); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /** |
| 100 | * Default constructor. |
| 101 | */ |
| 102 | public URLCodec() { |
| 103 | this(CharEncoding.UTF_8); |
| 104 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…