Class AbstractInputStreamContent (1.43.0)

public abstract class AbstractInputStreamContent implements HttpContent

Serializes HTTP request content from an input stream into an output stream.

The #type field is required. Subclasses should implement the #getLength(), #getInputStream(), and #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.

Inheritance

java.lang.Object > AbstractInputStreamContent

Implements

HttpContent

Constructors

AbstractInputStreamContent(String type)

public AbstractInputStreamContent(String type)
Parameter
NameDescription
typeString

Content type or null for none

Methods

getCloseInputStream()

public final boolean getCloseInputStream()

Returns whether the input stream should be closed at the end of #writeTo. Default is true.

Returns
TypeDescription
boolean

getInputStream()

public abstract InputStream getInputStream()

Return an input stream for the specific implementation type of AbstractInputStreamContent. If the specific implementation will return true for #retrySupported() this should be a factory function which will create a new InputStream from the source data whenever invoked.

Returns
TypeDescription
InputStream
Exceptions
TypeDescription
IOException

getType()

public String getType()

Returns the content type or null for none.

Returns
TypeDescription
String

setCloseInputStream(boolean closeInputStream)

public AbstractInputStreamContent setCloseInputStream(boolean closeInputStream)

Sets whether the input stream should be closed at the end of #writeTo. Default is true. Subclasses should override by calling super.

Parameter
NameDescription
closeInputStreamboolean
Returns
TypeDescription
AbstractInputStreamContent

setType(String type)

public AbstractInputStreamContent setType(String type)

Sets the content type or null for none. Subclasses should override by calling super.

Parameter
NameDescription
typeString
Returns
TypeDescription
AbstractInputStreamContent

writeTo(OutputStream out)

public void writeTo(OutputStream out)

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 output stream has not been closed, and will fail to work if it has been closed.

Parameter
NameDescription
outOutputStream
Exceptions
TypeDescription
IOException