com.google.api.client.http
Class ByteArrayContent

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

public final class ByteArrayContent
extends AbstractInputStreamContent

Concrete implementation of AbstractInputStreamContent that generates repeatable input streams based on the contents of byte array.

The AbstractInputStreamContent.type field is required.

Sample use:

 
  static void setRequestJsonContent(HttpRequest request, String json) {
    InputStreamContent content = new ByteArrayContent(json);
    content.type = "application/json";
    request.content = content;
  }
 
 

Since:
1.4
Author:
moshenko@google.com (Jacob Moshenko)

Field Summary
 
Fields inherited from class com.google.api.client.http.AbstractInputStreamContent
encoding, type
 
Constructor Summary
ByteArrayContent()
          Create an instance with no data.
ByteArrayContent(byte[] array)
           
ByteArrayContent(String contentString)
          Create an instance from the byte contents of the string.
 
Method Summary
protected  InputStream getInputStream()
          Return an input stream for the specific implementation type of AbstractInputStreamContent.
 long getLength()
          Returns the content length or less than zero if not known.
 boolean retrySupported()
          Returns whether or not retry is supported on this content type.
 
Methods inherited from class com.google.api.client.http.AbstractInputStreamContent
copy, getEncoding, getType, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayContent

public ByteArrayContent(byte[] array)
Parameters:
array - Data source for creating input streams.

ByteArrayContent

public ByteArrayContent(String contentString)
Create an instance from the byte contents of the string. This assumes that the string is encoded in UTF-8 and uses Strings.toBytesUtf8() to perform the conversion.

Parameters:
contentString - String to use as the source data for creating input streams

ByteArrayContent

public ByteArrayContent()
Create an instance with no data.

Method Detail

getLength

public long getLength()
Description copied from interface: HttpContent
Returns the content length or less than zero if not known.


retrySupported

public boolean retrySupported()
Description copied from interface: HttpContent
Returns whether or not retry is supported on this content type. This is a backward incompatible change that affects versions prior to 1.4.


getInputStream

protected InputStream getInputStream()
Description copied from class: AbstractInputStreamContent
Return an input stream for the specific implementation type of AbstractInputStreamContent. If the specific implementation will return true for HttpContent.retrySupported() this should be a factory function which will create a new InputStream from the source data whenever invoked.

Specified by:
getInputStream in class AbstractInputStreamContent


Copyright © 2010-2011 Google. All Rights Reserved.