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.

Sample use:

 
  static void setJsonContent(HttpRequest request, byte[] json) {
    request.setContent(new ByteArrayContent("application/json", json));
  }
 
 

Implementation is not thread-safe.

Since:
1.4
Author:
[email protected] (Jacob Moshenko)

Constructor Summary
ByteArrayContent(String type, byte[] array)
           
 
Method Summary
static ByteArrayContent fromString(String type, String contentString)
          Returns a new instance with the UTF-8 encoding (using Strings.toBytesUtf8()) of the given content string.
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.
 ByteArrayContent setEncoding(String encoding)
          Sets the content encoding (for example "gzip") or null for none.
 ByteArrayContent setType(String type)
          Sets the content type or null for none.
 
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(String type,
                        byte[] array)
Parameters:
type - content type or null for none
array - byte array content
Since:
1.5
Method Detail

fromString

public static ByteArrayContent fromString(String type,
                                          String contentString)
Returns a new instance with the UTF-8 encoding (using Strings.toBytesUtf8()) of the given content string.

Sample use:

 
  static void setJsonContent(HttpRequest request, String json) {
    request.setContent(ByteArrayContent.fromString("application/json", json));
  }
 
 

Parameters:
type - content type or null for none
contentString - content string
Since:
1.5

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.


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

setEncoding

public ByteArrayContent setEncoding(String encoding)
Description copied from class: AbstractInputStreamContent
Sets the content encoding (for example "gzip") or null for none.

Overrides:
setEncoding in class AbstractInputStreamContent

setType

public ByteArrayContent setType(String type)
Description copied from class: AbstractInputStreamContent
Sets the content type or null for none.

Overrides:
setType in class AbstractInputStreamContent


Copyright © 2011 Google. All Rights Reserved.