Class InputStreamContent
java.lang.Object
com.google.api.client.http.AbstractInputStreamContent
com.google.api.client.http.InputStreamContent
- All Implemented Interfaces:
HttpContent, StreamingContent
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final InputStreamInput stream to read from.private longContent length or less than zero if not known.private booleanWhether or not retry is supported. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn an input stream for the specific implementation type ofAbstractInputStreamContent.longReturns the content length or less than zero if not known.booleanReturns whether or not retry is supported on this content type.setCloseInputStream(boolean closeInputStream) Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(OutputStream).setLength(long length) Sets the content length or less than zero if not known.setRetrySupported(boolean retrySupported) Sets whether or not retry is supported.Sets the content type ornullfor none.Methods inherited from class AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
Field Details
-
length
private long lengthContent length or less than zero if not known. Defaults to-1. -
retrySupported
private boolean retrySupportedWhether or not retry is supported. Defaults tofalse. -
inputStream
Input stream to read from.
-
-
Constructor Details
-
InputStreamContent
- Parameters:
type- Content type ornullfor noneinputStream- Input stream to read from- Since:
- 1.5
-
-
Method Details
-
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
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
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
Description copied from class:AbstractInputStreamContentSets the content type ornullfor none. Subclasses should override by calling super.- Overrides:
setTypein classAbstractInputStreamContent
-
setCloseInputStream
Description copied from class:AbstractInputStreamContentSets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(OutputStream). Default istrue. Subclasses should override by calling super.- Overrides:
setCloseInputStreamin classAbstractInputStreamContent
-
setLength
Sets the content length or less than zero if not known.Defaults to
-1.- Since:
- 1.5
-