com.google.api.client.http
Class InputStreamContent

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

public final class InputStreamContent
extends AbstractInputStreamContent

Concrete implementation of AbstractInputStreamContent that simply handles the transfer of data from an input stream to an output stream. This should only be used for streams that can not be re-opened and retried. If you have a stream that it is possible to recreate please create a new subclass of AbstractInputStreamContent.

The input stream is guaranteed to be closed at the end of AbstractInputStreamContent.writeTo(OutputStream).

Sample use with a URL:

 
  private static void setRequestJpegContent(HttpRequest request, URL jpegUrl) throws IOException {
    request.setContent(new InputStreamContent("image/jpeg", jpegUrl.openStream()));
  }
 
 

Implementation is not thread-safe.

Since:
1.0
Author:
Yaniv Inbar

Field Summary
 InputStream inputStream
          Deprecated. (scheduled to be made private final in 1.6) Use getInputStream()
 long length
          Deprecated. (scheduled to be made private in 1.6) Use getLength() or setLength(long)
 
Fields inherited from class com.google.api.client.http.AbstractInputStreamContent
encoding, type
 
Constructor Summary
InputStreamContent()
          Deprecated. (scheduled to be removed in 1.6) Use InputStreamContent(String, InputStream)
InputStreamContent(String type, InputStream inputStream)
           
 
Method Summary
 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.
 InputStreamContent setEncoding(String encoding)
          Sets the content encoding (for example "gzip") or null for none.
 void setLength(long length)
          Sets the content length or less than zero if not known.
 InputStreamContent 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
 

Field Detail

length

@Deprecated
public long length
Deprecated. (scheduled to be made private in 1.6) Use getLength() or setLength(long)
Content length or less than zero if not known. Defaults to -1.


inputStream

@Deprecated
public InputStream inputStream
Deprecated. (scheduled to be made private final in 1.6) Use getInputStream()
Input stream to read from.

Constructor Detail

InputStreamContent

@Deprecated
public InputStreamContent()
Deprecated. (scheduled to be removed in 1.6) Use InputStreamContent(String, InputStream)


InputStreamContent

public InputStreamContent(String type,
                          InputStream inputStream)
Parameters:
type - Content type or null for none
inputStream - Input stream to read from
Since:
1.5
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.


getInputStream

public 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 InputStreamContent 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 InputStreamContent setType(String type)
Description copied from class: AbstractInputStreamContent
Sets the content type or null for none.

Overrides:
setType in class AbstractInputStreamContent

setLength

public void setLength(long length)
Sets the content length or less than zero if not known.

Defaults to -1.

Since:
1.5


Copyright © 2011 Google. All Rights Reserved.