public abstract class AbstractInputStreamContent extends Object implements HttpContent
The type
field is required. Subclasses should implement the HttpContent.getLength()
,
getInputStream()
, and HttpContent.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 use
ByteStreams.limit(InputStream, long)
.
Implementations don't need to be thread-safe.
Constructor and Description |
---|
AbstractInputStreamContent(String type) |
Modifier and Type | Method and Description |
---|---|
static void |
copy(InputStream inputStream,
OutputStream outputStream)
Deprecated.
(scheduled to be removed in 1.15) Use
IOUtils.copy(InputStream, OutputStream) instead |
static void |
copy(InputStream inputStream,
OutputStream outputStream,
boolean closeInputStream)
Deprecated.
(scheduled to be removed in 1.15) Use
IOUtils.copy(InputStream, OutputStream, boolean) instead |
boolean |
getCloseInputStream()
Returns whether the input stream should be closed at the end of
writeTo(java.io.OutputStream) . |
String |
getEncoding()
Deprecated.
|
abstract InputStream |
getInputStream()
Return an input stream for the specific implementation type of
AbstractInputStreamContent . |
String |
getType()
Returns the content type or
null for none. |
AbstractInputStreamContent |
setCloseInputStream(boolean closeInputStream)
Sets whether the input stream should be closed at the end of
writeTo(java.io.OutputStream) . |
AbstractInputStreamContent |
setEncoding(String encoding)
Deprecated.
(scheduled to be removed in 1.15) Use
HttpEncoding instead. |
AbstractInputStreamContent |
setType(String type)
Sets the content type or
null for none. |
void |
writeTo(OutputStream out)
Writes the byte content to the given output stream.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getLength, retrySupported
public AbstractInputStreamContent(String type)
type
- Content type or null
for nonepublic abstract InputStream getInputStream() throws IOException
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.IOException
public void writeTo(OutputStream out) throws IOException
HttpContent
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.
Upgrade warning: in prior version 1.13 the implementation of this method was allowed to close the stream, but starting with 1.14 closing the stream is no longer allowed.
writeTo
in interface HttpContent
writeTo
in interface StreamingContent
out
- output streamIOException
@Deprecated public String getEncoding()
HttpContent
"gzip"
) or null
for none.getEncoding
in interface HttpContent
public String getType()
HttpContent
null
for none.getType
in interface HttpContent
public final boolean getCloseInputStream()
writeTo(java.io.OutputStream)
. Default is
true
.@Deprecated public AbstractInputStreamContent setEncoding(String encoding)
HttpEncoding
instead."gzip"
) or null
for none. Subclasses
should override by calling super.public AbstractInputStreamContent setType(String type)
null
for none. Subclasses should override by calling super.public AbstractInputStreamContent setCloseInputStream(boolean closeInputStream)
writeTo(java.io.OutputStream)
. Default is
true
. Subclasses should override by calling super.@Deprecated public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException
IOUtils.copy(InputStream, OutputStream)
insteadThe input stream is guaranteed to be closed at the end of this method.
Sample use:
static void downloadMedia(HttpResponse response, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); try { AbstractInputStreamContent.copy(response.getContent(), out); } finally { out.close(); } }
inputStream
- source input streamoutputStream
- destination output streamIOException
@Deprecated public static void copy(InputStream inputStream, OutputStream outputStream, boolean closeInputStream) throws IOException
IOUtils.copy(InputStream, OutputStream, boolean)
insteadSample use:
static void downloadMedia(HttpResponse response, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); try { AbstractInputStreamContent.copy(response.getContent(), out, true); } finally { out.close(); } }
inputStream
- source input streamoutputStream
- destination output streamcloseInputStream
- whether the input stream should be closed at the end of this methodIOException
Copyright © 2011-2013 Google. All Rights Reserved.