jdk/src/share/classes/java/net/URLEncoder.java
changeset 19069 1d9cb0d080e3
parent 5506 202f599c92aa
child 21334 c60dfce46a77
child 21278 ef8a3a2a72f2
equal deleted inserted replaced
19068:f2358d18923a 19069:1d9cb0d080e3
     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 &quot;<code>a</code>&quot; through
    54  * <li>The alphanumeric characters &quot;{@code a}&quot; through
    55  *     &quot;<code>z</code>&quot;, &quot;<code>A</code>&quot; through
    55  *     &quot;{@code z}&quot;, &quot;{@code A}&quot; through
    56  *     &quot;<code>Z</code>&quot; and &quot;<code>0</code>&quot;
    56  *     &quot;{@code Z}&quot; and &quot;{@code 0}&quot;
    57  *     through &quot;<code>9</code>&quot; remain the same.
    57  *     through &quot;{@code 9}&quot; remain the same.
    58  * <li>The special characters &quot;<code>.</code>&quot;,
    58  * <li>The special characters &quot;{@code .}&quot;,
    59  *     &quot;<code>-</code>&quot;, &quot;<code>*</code>&quot;, and
    59  *     &quot;{@code -}&quot;, &quot;{@code *}&quot;, and
    60  *     &quot;<code>_</code>&quot; remain the same.
    60  *     &quot;{@code _}&quot; remain the same.
    61  * <li>The space character &quot;<code>&nbsp;</code>&quot; is
    61  * <li>The space character &quot; &nbsp; &quot; is
    62  *     converted into a plus sign &quot;<code>+</code>&quot;.
    62  *     converted into a plus sign &quot;{@code +}&quot;.
    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  *     &quot;<code>%<i>xy</i></code>&quot;, where <i>xy</i> is the
    66  *     &quot;<i>{@code %xy}</i>&quot;, 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      */