com.google.api.client.http
Class AbstractHttpContent

java.lang.Object
  extended by com.google.api.client.http.AbstractHttpContent
All Implemented Interfaces:
HttpContent
Direct Known Subclasses:
AbstractXmlHttpContent, JsonHttpContent, MultipartRelatedContent, ProtoHttpContent, UrlEncodedContent

public abstract class AbstractHttpContent
extends Object
implements HttpContent

Abstract implementation of an HTTP content with typical options.

Implementation is not thread-safe.

Since:
1.5
Author:
Yaniv Inbar

Constructor Summary
AbstractHttpContent()
           
 
Method Summary
protected  long computeLength()
          Computes and returns the content length or less than zero if not known.
 String getEncoding()
          Default implementation returns null, but subclasses may override.
 long getLength()
          Default implementation calls computeLength() once and caches it for future invocations, but subclasses may override.
 boolean retrySupported()
          Default implementation returns true, but subclasses may override.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.api.client.http.HttpContent
getType, writeTo
 

Constructor Detail

AbstractHttpContent

public AbstractHttpContent()
Method Detail

getEncoding

public String getEncoding()
Default implementation returns null, but subclasses may override.

Specified by:
getEncoding in interface HttpContent

getLength

public long getLength()
               throws IOException
Default implementation calls computeLength() once and caches it for future invocations, but subclasses may override.

Specified by:
getLength in interface HttpContent
Throws:
IOException

computeLength

protected long computeLength()
                      throws IOException
Computes and returns the content length or less than zero if not known.

Subclasses may override, but by default this computes the length by calling HttpContent.writeTo(OutputStream) with an output stream that does not process the bytes written, but only retains the count of bytes. If retrySupported() is false, it will instead return -1.

Throws:
IOException

retrySupported

public boolean retrySupported()
Default implementation returns true, but subclasses may override.

Specified by:
retrySupported in interface HttpContent


Copyright © 2011-2012 Google. All Rights Reserved.