All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.net.URLEncoder Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
/*

This is not an official specification document, and usage is restricted.

NOTICE


(c) 2005-2007 Sun Microsystems, Inc. All Rights Reserved.

Neither this file nor any files generated from it describe a complete specification, and they may only be used as described below. For example, no permission is given for you to incorporate this file, in whole or in part, in an implementation of a Java specification.

Sun Microsystems Inc. owns the copyright in this file and it is provided to you for informative, as opposed to normative, use. The file and any files generated from it may be used to generate other informative documentation, such as a unified set of documents of API signatures for a platform that includes technologies expressed as Java APIs. The file may also be used to produce "compilation stubs," which allow applications to be compiled and validated for such platforms.

Any work generated from this file, such as unified javadocs or compiled stub files, must be accompanied by this notice in its entirety.

This work corresponds to the API signatures of JSR 219: Foundation Profile 1.1. In the event of a discrepency between this work and the JSR 219 specification, which is available at http://www.jcp.org/en/jsr/detail?id=219, the latter takes precedence. */ package java.net; import java.io.ByteArrayOutputStream; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.BitSet; import java.security.AccessController; import java.security.PrivilegedAction; /** * Utility class for HTML form encoding. This class contains static methods * for converting a String to the application/x-www-form-urlencoded MIME * format. For more information about HTML form encoding, consult the HTML * specification. * *

* When encoding a String, the following rules apply: * *

*

    *
  • The alphanumeric characters "a" through * "z", "A" through * "Z" and "0" * through "9" remain the same. *
  • The special characters ".", * "-", "*", and * "_" remain the same. *
  • The space character " " is * converted into a plus sign "+". *
  • All other characters are unsafe and are first converted into * one or more bytes using some encoding scheme. Then each byte is * represented by the 3-character string * "%xy", where xy is the * two-digit hexadecimal representation of the byte. * The recommended encoding scheme to use is UTF-8. However, * for compatibility reasons, if an encoding is not specified, * then the default encoding of the platform is used. *
* *

* For example using UTF-8 as the encoding scheme the string "The * string ü@foo-bar" would get converted to * "The+string+%C3%BC%40foo-bar" because in UTF-8 the character * ü is encoded as two bytes C3 (hex) and BC (hex), and the * character @ is encoded as one byte 40 (hex). * * @author Herb Jellinek * @version 1.18, 02/02/00 * @since JDK1.0 */ public class URLEncoder { /* * This hidden constructor does not necessarily correspond to * a constructor in the original source file -- it keeps javadoc * from generating an inappropriate default constructor. */ private URLEncoder() { } /** * Translates a string into x-www-form-urlencoded * format. This method uses the platform's default encoding * as the encoding scheme to obtain the bytes for unsafe characters. * * @param s String to be translated. * @deprecated The resulting string may vary depending on the platform's * default encoding. Instead, use the encode(String,String) * method to specify the encoding. * @return the translated String. */ public static String encode(String s) { return null; } /** * Translates a string into application/x-www-form-urlencoded * format using a specific encoding scheme. This method uses the * supplied encoding scheme to obtain the bytes for unsafe * characters. *

* Note: The * World Wide Web Consortium Recommendation states that * UTF-8 should be used. Not doing so may introduce * incompatibilites. * * @param s String to be translated. * @param enc The name of a supported * character * encoding. * @return the translated String. * @exception UnsupportedEncodingException * If the named encoding is not supported * @see URLDecoder#decode(java.lang.String, java.lang.String) * @since 1.4 */ public static String encode(String s, String enc) throws UnsupportedEncodingException { return null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy