Package com.google.api.client.http
Class AbstractInputStreamContent
- java.lang.Object
-
- com.google.api.client.http.AbstractInputStreamContent
-
- All Implemented Interfaces:
HttpContent
,StreamingContent
- Direct Known Subclasses:
ByteArrayContent
,FileContent
,InputStreamContent
public abstract class AbstractInputStreamContent extends Object implements HttpContent
Serializes HTTP request content from an input stream into an output stream.The
type
field is required. Subclasses should implement theHttpContent.getLength()
,getInputStream()
, andHttpContent.retrySupported()
for their specific type of input stream. By default, all content is read from the input stream. If instead you want to limit the maximum amount of content read from the input stream, you may useByteStreams.limit(InputStream, long)
.Implementations don't need to be thread-safe.
- Since:
- 1.4
- Author:
- moshenko@google.com (Jacob Moshenko)
-
-
Constructor Summary
Constructors Constructor Description AbstractInputStreamContent(String type)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
getCloseInputStream()
Returns whether the input stream should be closed at the end ofwriteTo(java.io.OutputStream)
.abstract InputStream
getInputStream()
Return an input stream for the specific implementation type ofAbstractInputStreamContent
.String
getType()
Returns the content type ornull
for none.AbstractInputStreamContent
setCloseInputStream(boolean closeInputStream)
Sets whether the input stream should be closed at the end ofwriteTo(java.io.OutputStream)
.AbstractInputStreamContent
setType(String type)
Sets the content type ornull
for none.void
writeTo(OutputStream out)
Writes the byte content to the given output stream.-
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
getLength, retrySupported
-
-
-
-
Constructor Detail
-
AbstractInputStreamContent
public AbstractInputStreamContent(String type)
- Parameters:
type
- Content type ornull
for none- Since:
- 1.5
-
-
Method Detail
-
getInputStream
public abstract InputStream getInputStream() throws IOException
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.- Throws:
IOException
- Since:
- 1.7
-
writeTo
public void writeTo(OutputStream out) throws IOException
Description copied from interface:StreamingContent
Writes the byte content to the given output stream.Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the the output stream has not been closed, and will fail to work if it has been closed.
- Specified by:
writeTo
in interfaceHttpContent
- Specified by:
writeTo
in interfaceStreamingContent
- Parameters:
out
- output stream- Throws:
IOException
-
getType
public String getType()
Description copied from interface:HttpContent
Returns the content type ornull
for none.- Specified by:
getType
in interfaceHttpContent
-
getCloseInputStream
public final boolean getCloseInputStream()
Returns whether the input stream should be closed at the end ofwriteTo(java.io.OutputStream)
. Default istrue
.- Since:
- 1.7
-
setType
public AbstractInputStreamContent setType(String type)
Sets the content type ornull
for none. Subclasses should override by calling super.- Since:
- 1.5
-
setCloseInputStream
public AbstractInputStreamContent setCloseInputStream(boolean closeInputStream)
Sets whether the input stream should be closed at the end ofwriteTo(java.io.OutputStream)
. Default istrue
. Subclasses should override by calling super.- Since:
- 1.7
-
-