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
Implements support for HTTP form content encoding serialization of type
application/x-www-form-urlencoded
as 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
FieldsModifier and TypeFieldDescriptionprivate Object
Key name/value data.private boolean
Use URI Path encoder flag. -
Constructor Summary
ConstructorsConstructorDescriptionUrlEncodedContent
(Object data) Initialize the UrlEncodedContent with the legacy and deprecated escapeUri encoderUrlEncodedContent
(Object data, boolean useUriPathEncoding) Initialize the UrlEncodedContent with or without the legacy and deprecated escapeUri encoder -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
appendParam
(boolean first, Writer writer, String name, Object value, boolean uriPathEncodingFlag) 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
).final Object
getData()
Returns the key name/value data ornull
for none.Sets the key name/value data.setMediaType
(HttpMediaType mediaType) Sets the media type to use for the Content-Type header, ornull
if unspecified.void
writeTo
(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
-
Field Details
-
data
Key name/value data. -
uriPathEncodingFlag
private boolean uriPathEncodingFlagUse URI Path encoder flag. False by default (use legacy and deprecated escapeUri)
-
-
Constructor Details
-
UrlEncodedContent
Initialize the UrlEncodedContent with the legacy and deprecated escapeUri encoder- Parameters:
data
- key name/value data
-
UrlEncodedContent
Initialize the UrlEncodedContent with or without the legacy and deprecated escapeUri encoder- Parameters:
data
- key name/value datauseUriPathEncoding
- escapes the string value so it can be safely included in URI path segments. For details on escaping URIs, see RFC 3986 - section 2.4
-
-
Method Details
-
writeTo
Description copied from interface:StreamingContent
Writes 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 output stream has not been closed, and will fail to work if it has been closed.
- Parameters:
out
- output stream- Throws:
IOException
-
setMediaType
Description copied from class:AbstractHttpContent
Sets the media type to use for the Content-Type header, ornull
if 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:
setMediaType
in classAbstractHttpContent
-
getData
Returns the key name/value data ornull
for none.- Since:
- 1.5
-
setData
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
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:
ClassCastException
- if the HTTP request has a content defined that is notUrlEncodedContent
- Since:
- 1.7
-
appendParam
private static boolean appendParam(boolean first, Writer writer, String name, Object value, boolean uriPathEncodingFlag) throws IOException - Throws:
IOException
-