Package com.google.api.client.http
Class InputStreamContent
- java.lang.Object
-
- com.google.api.client.http.AbstractInputStreamContent
-
- com.google.api.client.http.InputStreamContent
-
- All Implemented Interfaces:
HttpContent,StreamingContent
public final class InputStreamContent extends AbstractInputStreamContent
Concrete implementation ofAbstractInputStreamContentthat 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 ofAbstractInputStreamContent.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
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.InputStreaminputStreamInput stream to read from.private longlengthContent length or less than zero if not known.private booleanretrySupportedWhether or not retry is supported.
-
Constructor Summary
Constructors Constructor Description InputStreamContent(java.lang.String type, java.io.InputStream inputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStreamgetInputStream()Return an input stream for the specific implementation type ofAbstractInputStreamContent.longgetLength()Returns the content length or less than zero if not known.booleanretrySupported()Returns whether or not retry is supported on this content type.InputStreamContentsetCloseInputStream(boolean closeInputStream)Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream).InputStreamContentsetLength(long length)Sets the content length or less than zero if not known.InputStreamContentsetRetrySupported(boolean retrySupported)Sets whether or not retry is supported.InputStreamContentsetType(java.lang.String type)Sets the content type ornullfor none.-
Methods inherited from class com.google.api.client.http.AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
-
-
-
Method Detail
-
getLength
public long getLength()
Description copied from interface:HttpContentReturns the content length or less than zero if not known.
-
retrySupported
public boolean retrySupported()
Description copied from interface:HttpContentReturns whether or not retry is supported on this content type.
-
setRetrySupported
public InputStreamContent setRetrySupported(boolean retrySupported)
Sets whether or not retry is supported. Defaults tofalse.Should be set to
trueifgetInputStream()is called to reset to the original position of the input stream.- Since:
- 1.7
-
getInputStream
public java.io.InputStream getInputStream()
Description copied from class:AbstractInputStreamContentReturn an input stream for the specific implementation type ofAbstractInputStreamContent. If the specific implementation will returntrueforHttpContent.retrySupported()this should be a factory function which will create a newInputStreamfrom the source data whenever invoked.- Specified by:
getInputStreamin classAbstractInputStreamContent
-
setType
public InputStreamContent setType(java.lang.String type)
Description copied from class:AbstractInputStreamContentSets the content type ornullfor none. Subclasses should override by calling super.- Overrides:
setTypein classAbstractInputStreamContent
-
setCloseInputStream
public InputStreamContent setCloseInputStream(boolean closeInputStream)
Description copied from class:AbstractInputStreamContentSets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream). Default istrue. Subclasses should override by calling super.- Overrides:
setCloseInputStreamin classAbstractInputStreamContent
-
setLength
public InputStreamContent setLength(long length)
Sets the content length or less than zero if not known.Defaults to
-1.- Since:
- 1.5
-
-