Package com.google.api.client.http
Class UrlEncodedContent
- java.lang.Object
-
- com.google.api.client.http.AbstractHttpContent
-
- com.google.api.client.http.UrlEncodedContent
-
- All Implemented Interfaces:
HttpContent,StreamingContent
public class UrlEncodedContent extends AbstractHttpContent
Implements support for HTTP form content encoding serialization of typeapplication/x-www-form-urlencodedas specified in the HTML 4.0 Specification.Sample usage:
static void setContent(HttpRequest request, Object item) { request.setContent(new UrlEncodedContent(item)); }Implementation is not thread-safe.
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ObjectdataKey name/value data.
-
Constructor Summary
Constructors Constructor Description UrlEncodedContent(java.lang.Object data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleanappendParam(boolean first, java.io.Writer writer, java.lang.String name, java.lang.Object value)static UrlEncodedContentgetContent(HttpRequest request)Returns the URL-encoded content of the given HTTP request, or if none return and set as content a new instance ofUrlEncodedContent(whosegetData()is an implementation ofMap).java.lang.ObjectgetData()Returns the key name/value data ornullfor none.UrlEncodedContentsetData(java.lang.Object data)Sets the key name/value data.UrlEncodedContentsetMediaType(HttpMediaType mediaType)Sets the media type to use for the Content-Type header, ornullif unspecified.voidwriteTo(java.io.OutputStream out)Writes the byte content to the given output stream.-
Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, computeLength, getCharset, getLength, getMediaType, getType, retrySupported
-
-
-
-
Method Detail
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionDescription copied from interface:StreamingContentWrites the byte content to the given output stream.Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the the output stream has not been closed, and will fail to work if it has been closed.
- Parameters:
out- output stream- Throws:
java.io.IOException
-
setMediaType
public UrlEncodedContent setMediaType(HttpMediaType mediaType)
Description copied from class:AbstractHttpContentSets the media type to use for the Content-Type header, ornullif unspecified.This will also overwrite any previously set parameter of the media type (for example
"charset"), and therefore might change other properties as well.- Overrides:
setMediaTypein classAbstractHttpContent
-
getData
public final java.lang.Object getData()
Returns the key name/value data ornullfor none.- Since:
- 1.5
-
setData
public UrlEncodedContent setData(java.lang.Object data)
Sets the key name/value data.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getContent
public static UrlEncodedContent getContent(HttpRequest request)
Returns the URL-encoded content of the given HTTP request, or if none return and set as content a new instance ofUrlEncodedContent(whosegetData()is an implementation ofMap).- Parameters:
request- HTTP request- Returns:
- URL-encoded content
- Throws:
java.lang.ClassCastException- if the HTTP request has a content defined that is notUrlEncodedContent- Since:
- 1.7
-
appendParam
private static boolean appendParam(boolean first, java.io.Writer writer, java.lang.String name, java.lang.Object value) throws java.io.IOException- Throws:
java.io.IOException
-
-