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 ofAbstractInputStreamContent
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 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
- Author:
- Yaniv Inbar
-
-
Constructor Summary
Constructors Constructor Description InputStreamContent(String type, InputStream inputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStream
getInputStream()
Return an input stream for the specific implementation type ofAbstractInputStreamContent
.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
setCloseInputStream(boolean closeInputStream)
Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream)
.InputStreamContent
setLength(long length)
Sets the content length or less than zero if not known.InputStreamContent
setRetrySupported(boolean retrySupported)
Sets whether or not retry is supported.InputStreamContent
setType(String type)
Sets the content type ornull
for none.-
Methods inherited from class com.google.api.client.http.AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
-
-
-
Constructor Detail
-
InputStreamContent
public InputStreamContent(String type, InputStream inputStream)
- Parameters:
type
- Content type ornull
for noneinputStream
- 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.
-
setRetrySupported
public InputStreamContent setRetrySupported(boolean retrySupported)
Sets whether or not retry is supported. Defaults tofalse
.Should be set to
true
ifgetInputStream()
is called to reset to the original position of the input stream.- Since:
- 1.7
-
getInputStream
public InputStream getInputStream()
Description copied from class:AbstractInputStreamContent
Return an input stream for the specific implementation type ofAbstractInputStreamContent
. If the specific implementation will returntrue
forHttpContent.retrySupported()
this should be a factory function which will create a newInputStream
from the source data whenever invoked.- Specified by:
getInputStream
in classAbstractInputStreamContent
-
setType
public InputStreamContent setType(String type)
Description copied from class:AbstractInputStreamContent
Sets the content type ornull
for none. Subclasses should override by calling super.- Overrides:
setType
in classAbstractInputStreamContent
-
setCloseInputStream
public InputStreamContent setCloseInputStream(boolean closeInputStream)
Description copied from class:AbstractInputStreamContent
Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream)
. Default istrue
. Subclasses should override by calling super.- Overrides:
setCloseInputStream
in classAbstractInputStreamContent
-
setLength
public InputStreamContent setLength(long length)
Sets the content length or less than zero if not known.Defaults to
-1
.- Since:
- 1.5
-
-