public final class InputStreamContent extends AbstractInputStreamContent
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.
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.
| Constructor and Description |
|---|
InputStreamContent(String
|
| Modifier and Type | Method and Description |
|---|---|
InputStream |
getInputStream()
Return an input stream for the specific implementation type of
AbstractInputStreamContent.
|
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 of
AbstractInputStreamContent.
|
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
Sets the content type or
null for none.
|
getCloseInputStream, getType, writeTopublic InputStreamContent(Stringtype, InputStream inputStream)
type - Content type or
null for none
inputStream - Input stream to read from
public long getLength()
HttpContent
public boolean retrySupported()
HttpContent
public InputStreamContentsetRetrySupported(boolean retrySupported)
false.
Should be set to true if getInputStream() is called to reset to the original position of the input stream.
public InputStreamgetInputStream()
AbstractInputStreamContent
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.
public InputStreamContentsetType(String type)
AbstractInputStreamContent
null for none. Subclasses should override by calling super.
public InputStreamContentsetCloseInputStream(boolean closeInputStream)
AbstractInputStreamContent
AbstractInputStreamContent.writeTo(java.io.OutputStream) . Default is
true. Subclasses should override by calling super.
public InputStreamContentsetLength(long length)
Defaults to -1.