com.google.api.client.http
Class UrlEncodedContent

java.lang.Object
  extended by com.google.api.client.http.AbstractHttpContent
      extended by com.google.api.client.http.UrlEncodedContent
All Implemented Interfaces:
HttpContent

public class UrlEncodedContent
extends AbstractHttpContent

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
Author:
Yaniv Inbar

Constructor Summary
UrlEncodedContent(Object data)
           Upgrade warning: prior to version 1.11 the data parameter could be null but now instead it throws a NullPointerException.
 
Method Summary
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 of UrlEncodedContent (whose getData() is an implementation of Map).
 Object getData()
          Returns the key name/value data or null for none.
 UrlEncodedContent setData(Object data)
          Sets the key name/value data.
 UrlEncodedContent setMediaType(HttpMediaType mediaType)
          Sets the media type to use for the Content-Type header, or null if unspecified.
 void writeTo(OutputStream out)
          Writes the content to the given output stream.
 
Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, getCharset, getEncoding, getLength, getMediaType, getType, retrySupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlEncodedContent

public UrlEncodedContent(Object data)

Upgrade warning: prior to version 1.11 the data parameter could be null but now instead it throws a NullPointerException.

Parameters:
data - key name/value data
Method Detail

writeTo

public void writeTo(OutputStream out)
             throws IOException
Description copied from interface: HttpContent
Writes the content to the given output stream.

The recommendation for implementations is that they should not close the output stream. Callers should not assume whether or not the output stream has been closed. Implementations that do not close the output stream should flush it at the end of the method.

Throws:
IOException

setMediaType

public UrlEncodedContent setMediaType(HttpMediaType mediaType)
Description copied from class: AbstractHttpContent
Sets the media type to use for the Content-Type header, or null 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 class AbstractHttpContent

getData

public final Object getData()
Returns the key name/value data or null for none.

Since:
1.5

setData

public UrlEncodedContent setData(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.

Upgrade warning: prior to version 1.11 the data parameter could be null but now instead it throws a NullPointerException.

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 of UrlEncodedContent (whose getData() is an implementation of Map).

Parameters:
request - HTTP request
Returns:
URL-encoded content
Throws:
ClassCastException - if the HTTP request has a content defined that is not UrlEncodedContent
Since:
1.7


Copyright © 2011-2012 Google. All Rights Reserved.