Class CGIParser
More information about this class is available from ostermiller.org.
- Since:
- ostermillerutils 1.00.00
- Author:
- Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
-
Constructor Summary
ConstructorsConstructorDescriptionCGIParser(InputStream in) Deprecated.This method does not decode URLEncoded values properly.CGIParser(InputStream in, String charset) Extract the name, value pairs from the given input stream and make them available for retrieval.Deprecated.This method does not decode URLEncoded values properly.Extract the name, value pairs from the given reader and make them available for retrieval.Deprecated.This method does not decode URLEncoded values properly.Extract the name, value pairs from the given string and make them available for retrieval. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParameter(String name, String value) Set a name value pair as used in a URL.voidaddParameter(String name, String[] values) Set a name value pair as used in a URL.getParameter(String name) Returns the value of a request parameter as a String, or null if the parameter does not exist.String[]Returns the names of the parameters contained in this request.Returns an Enumeration of String objects containing the names of the parameters contained in this request.Get the all the parameters in the order in which they were added.String[]getParameterValues(String name) Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.voidsetParameter(String name, String value) Set a name value pair as used in a URL.voidsetParameter(String name, String[] values) Set a name value pair as used in a URL.toString()Returns the name value pairs properly escaped and written in URL format with UTF-8 URL encoding.Returns the name value pairs properly escaped and written in URL format.
-
Constructor Details
-
CGIParser
Deprecated.This method does not decode URLEncoded values properly. Please use a method that specifies a character set.Extract the name, value pairs from the given input stream and make them available for retrieval.The stream is read until the stream contains no more bytes.
Byte to character conversion on the stream is done according the platforms default character encoding.
- Parameters:
in- Stream containing CGI Encoded name value pairs.- Throws:
IOException- If an input error occurs- Since:
- ostermillerutils 1.00.00
-
CGIParser
Extract the name, value pairs from the given input stream and make them available for retrieval.The stream is read until the stream contains no more bytes.
The character set is used both when converting the byte stream to a character stream and when decoding URL decoded parameters.
- Parameters:
in- Stream containing CGI Encoded name value pairs.charset- Character encoding to use when converting bytes to characters- Throws:
IOException- If an input error occursUnsupportedEncodingException- If the character set provided is not recognized- Since:
- ostermillerutils 1.03.00
-
CGIParser
Deprecated.This method does not decode URLEncoded values properly. Please use a method that specifies a character set.Extract the name, value pairs from the given reader and make them available for retrieval.The reader is read until the stream contains no more characters.
- Parameters:
in- Reader containing CGI Encoded name value pairs.- Throws:
IOException- If an input error occurs- Since:
- ostermillerutils 1.00.00
-
CGIParser
Extract the name, value pairs from the given reader and make them available for retrieval.The reader is read until the stream contains no more characters.
- Parameters:
in- Reader containing CGI Encoded name value pairs.charset- Character encoding to use when converting bytes to characters- Throws:
IOException- If an input error occursUnsupportedEncodingException- If the character set provided is not recognized- Since:
- ostermillerutils 1.03.00
-
CGIParser
Deprecated.This method does not decode URLEncoded values properly. Please use a method that specifies a character set.Extract the name, value pairs from the given string and make them available for retrieval.- Parameters:
s- CGI Encoded name value pairs.- Since:
- ostermillerutils 1.00.00
-
CGIParser
Extract the name, value pairs from the given string and make them available for retrieval.- Parameters:
s- CGI Encoded name value pairs.charset- Character encoding to use when converting bytes to characters- Throws:
UnsupportedEncodingException- If the character set provided is not recognized- Since:
- ostermillerutils 1.03.00
-
-
Method Details
-
getParameterValues
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.If the parameter has a single value, the array has a length of 1.
- Parameters:
name- a String containing the name of the parameter whose value is requested- Returns:
- an array of String objects containing the parameter's values
- Since:
- ostermillerutils 1.00.00
-
setParameter
Set a name value pair as used in a URL. This method will replace any previously defined values with the single value specified. If the value is null, the name is removed.- Parameters:
name- a String specifying the name of the parameter.value- a String specifying the value of the single parameter, or null to remove.- Since:
- ostermillerutils 1.02.15
-
setParameter
Set a name value pair as used in a URL. This method will replace any previously defined values with the single value specified. If values is null or empty, the name is removed.- Parameters:
name- a String specifying the name of the parameter.values- a String array specifying the values for the parameter, or null to remove.- Throws:
NullPointerException- if any of the values is null.- Since:
- ostermillerutils 1.02.15
-
addParameter
Set a name value pair as used in a URL. This method will add to any previously defined values the values specified. If value is null, this method has no effect.- Parameters:
name- a String specifying the name of the parameter.value- a String specifying the value of the single parameter, or null to remove.- Since:
- ostermillerutils 1.02.15
-
addParameter
Set a name value pair as used in a URL. This method will add to any previously defined values the values specified. If values is null, this method has no effect.- Parameters:
name- a String specifying the name of the parameter.values- a String array specifying the values of the parameter, or null to remove.- Throws:
NullPointerException- if any of the values is null.- Since:
- ostermillerutils 1.02.15
-
getParameter
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request.You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String).
If you use this method with a multiple valued parameter, the value returned is equal to the first value in the array returned by getParameterValues.
- Parameters:
name- a String specifying the name of the parameter- Returns:
- a String representing the single value of the parameter
- Since:
- ostermillerutils 1.00.00
-
getParameterNames
Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.- Returns:
- an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters
- Since:
- ostermillerutils 1.00.00
-
getParameterNameList
Returns the names of the parameters contained in this request. If the request has no parameters, the method returns an empty String array. Each name will appear only once, even if it was contained in the request multiple times. The order of the names may not match the order from the request.- Returns:
- An array of Strings, each of which is the name of a request parameter; or an array of length zero if the request has no parameters
- Since:
- ostermillerutils 1.03.00
-
getParameters
Get the all the parameters in the order in which they were added.- Returns:
- array of all name value pairs.
-
toString
Returns the name value pairs properly escaped and written in URL format.- Parameters:
enc- Character encoding to use when escaping characters.- Returns:
- URLEncoded name value pairs.
- Throws:
UnsupportedEncodingException- If the named encoding is not supported.- Since:
- ostermillerutils 1.00.00
-
toString
Returns the name value pairs properly escaped and written in URL format with UTF-8 URL encoding.
-