1 /* |
1 /* |
2 * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
49 * <p> |
49 * <p> |
50 * When encoding a String, the following rules apply: |
50 * When encoding a String, the following rules apply: |
51 * |
51 * |
52 * <p> |
52 * <p> |
53 * <ul> |
53 * <ul> |
54 * <li>The alphanumeric characters "<code>a</code>" through |
54 * <li>The alphanumeric characters "{@code a}" through |
55 * "<code>z</code>", "<code>A</code>" through |
55 * "{@code z}", "{@code A}" through |
56 * "<code>Z</code>" and "<code>0</code>" |
56 * "{@code Z}" and "{@code 0}" |
57 * through "<code>9</code>" remain the same. |
57 * through "{@code 9}" remain the same. |
58 * <li>The special characters "<code>.</code>", |
58 * <li>The special characters "{@code .}", |
59 * "<code>-</code>", "<code>*</code>", and |
59 * "{@code -}", "{@code *}", and |
60 * "<code>_</code>" remain the same. |
60 * "{@code _}" remain the same. |
61 * <li>The space character "<code> </code>" is |
61 * <li>The space character " " is |
62 * converted into a plus sign "<code>+</code>". |
62 * converted into a plus sign "{@code +}". |
63 * <li>All other characters are unsafe and are first converted into |
63 * <li>All other characters are unsafe and are first converted into |
64 * one or more bytes using some encoding scheme. Then each byte is |
64 * one or more bytes using some encoding scheme. Then each byte is |
65 * represented by the 3-character string |
65 * represented by the 3-character string |
66 * "<code>%<i>xy</i></code>", where <i>xy</i> is the |
66 * "<i>{@code %xy}</i>", where <i>xy</i> is the |
67 * two-digit hexadecimal representation of the byte. |
67 * two-digit hexadecimal representation of the byte. |
68 * The recommended encoding scheme to use is UTF-8. However, |
68 * The recommended encoding scheme to use is UTF-8. However, |
69 * for compatibility reasons, if an encoding is not specified, |
69 * for compatibility reasons, if an encoding is not specified, |
70 * then the default encoding of the platform is used. |
70 * then the default encoding of the platform is used. |
71 * </ul> |
71 * </ul> |
150 * You can't call the constructor. |
150 * You can't call the constructor. |
151 */ |
151 */ |
152 private URLEncoder() { } |
152 private URLEncoder() { } |
153 |
153 |
154 /** |
154 /** |
155 * Translates a string into <code>x-www-form-urlencoded</code> |
155 * Translates a string into {@code x-www-form-urlencoded} |
156 * format. This method uses the platform's default encoding |
156 * format. This method uses the platform's default encoding |
157 * as the encoding scheme to obtain the bytes for unsafe characters. |
157 * as the encoding scheme to obtain the bytes for unsafe characters. |
158 * |
158 * |
159 * @param s <code>String</code> to be translated. |
159 * @param s {@code String} to be translated. |
160 * @deprecated The resulting string may vary depending on the platform's |
160 * @deprecated The resulting string may vary depending on the platform's |
161 * default encoding. Instead, use the encode(String,String) |
161 * default encoding. Instead, use the encode(String,String) |
162 * method to specify the encoding. |
162 * method to specify the encoding. |
163 * @return the translated <code>String</code>. |
163 * @return the translated {@code String}. |
164 */ |
164 */ |
165 @Deprecated |
165 @Deprecated |
166 public static String encode(String s) { |
166 public static String encode(String s) { |
167 |
167 |
168 String str = null; |
168 String str = null; |
175 |
175 |
176 return str; |
176 return str; |
177 } |
177 } |
178 |
178 |
179 /** |
179 /** |
180 * Translates a string into <code>application/x-www-form-urlencoded</code> |
180 * Translates a string into {@code application/x-www-form-urlencoded} |
181 * format using a specific encoding scheme. This method uses the |
181 * format using a specific encoding scheme. This method uses the |
182 * supplied encoding scheme to obtain the bytes for unsafe |
182 * supplied encoding scheme to obtain the bytes for unsafe |
183 * characters. |
183 * characters. |
184 * <p> |
184 * <p> |
185 * <em><strong>Note:</strong> The <a href= |
185 * <em><strong>Note:</strong> The <a href= |
186 * "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars"> |
186 * "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars"> |
187 * World Wide Web Consortium Recommendation</a> states that |
187 * World Wide Web Consortium Recommendation</a> states that |
188 * UTF-8 should be used. Not doing so may introduce |
188 * UTF-8 should be used. Not doing so may introduce |
189 * incompatibilites.</em> |
189 * incompatibilites.</em> |
190 * |
190 * |
191 * @param s <code>String</code> to be translated. |
191 * @param s {@code String} to be translated. |
192 * @param enc The name of a supported |
192 * @param enc The name of a supported |
193 * <a href="../lang/package-summary.html#charenc">character |
193 * <a href="../lang/package-summary.html#charenc">character |
194 * encoding</a>. |
194 * encoding</a>. |
195 * @return the translated <code>String</code>. |
195 * @return the translated {@code String}. |
196 * @exception UnsupportedEncodingException |
196 * @exception UnsupportedEncodingException |
197 * If the named encoding is not supported |
197 * If the named encoding is not supported |
198 * @see URLDecoder#decode(java.lang.String, java.lang.String) |
198 * @see URLDecoder#decode(java.lang.String, java.lang.String) |
199 * @since 1.4 |
199 * @since 1.4 |
200 */ |
200 */ |