Top Description Fields Constructors Methods
org.apache.http.entity

public Class InputStreamEntity

extends AbstractHttpEntity
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, org.apache.http.util.Args

A streamed, non-repeatable entity that obtains its content from an InputStream.
Since
4.0

Field Summary

Modifier and TypeField and Description
private final InputStream
private final long
Inherited from org.apache.http.entity.AbstractHttpEntity:
chunkedcontentEncodingcontentTypeOUTPUT_BUFFER_SIZE

Constructor Summary

AccessConstructor and Description
public
InputStreamEntity(final InputStream
input stream
inStream
)

Creates an entity with an unknown length.

public
InputStreamEntity(final InputStream
input stream
inStream
,
final long
of the input stream, -1 if unknown
length
)

Creates an entity with a specified content length.

public
InputStreamEntity(final InputStream
input stream
inStream
,
final ContentType
content type
contentType
)

Creates an entity with a content type and unknown length.

public
InputStreamEntity(final InputStream
input stream
inStream
,
final long
of the input stream, -1 if unknown
length
,
final ContentType
for specifying the Content-Type header, may be null
contentType
)

Method Summary

Modifier and TypeMethod and Description
public InputStream
getContent()

Implements org.apache.http.HttpEntity.getContent.

Returns a content stream of the entity.
public long

Returns:

the content length or -1 if unknown
getContentLength
()

Implements org.apache.http.HttpEntity.getContentLength.

Tells the length of the content, if known.
public boolean
isRepeatable()

Implements org.apache.http.HttpEntity.isRepeatable.

Tells if the entity is capable of producing its data more than once.
public boolean
isStreaming()

Implements org.apache.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream.
public void
writeTo(final OutputStream
the output stream to write entity content to
outStream
)

Implements org.apache.http.HttpEntity.writeTo.

Writes bytes from the InputStream this entity was constructed with to an OutputStream.
Inherited from org.apache.http.entity.AbstractHttpEntity:
consumeContentgetContentEncodinggetContentTypeisChunkedsetChunkedsetContentEncodingsetContentEncodingsetContentTypesetContentTypetoString

Field Detail

contentback to summary
private final InputStream content
lengthback to summary
private final long length

Constructor Detail

InputStreamEntityback to summary
public InputStreamEntity(final InputStream inStream)

Creates an entity with an unknown length. Equivalent to new InputStreamEntity(inStream, -1).

Parameters
inStream:InputStream

input stream

Exceptions
IllegalArgumentException:
if inStream is null
Since
4.3
InputStreamEntityback to summary
public InputStreamEntity(final InputStream inStream, final long length)

Creates an entity with a specified content length.

Parameters
inStream:InputStream

input stream

length:long

of the input stream, -1 if unknown

Exceptions
IllegalArgumentException:
if inStream is null
InputStreamEntityback to summary
public InputStreamEntity(final InputStream inStream, final ContentType contentType)

Creates an entity with a content type and unknown length. Equivalent to new InputStreamEntity(inStream, -1, contentType).

Parameters
inStream:InputStream

input stream

contentType:ContentType

content type

Exceptions
IllegalArgumentException:
if inStream is null
Since
4.3
InputStreamEntityback to summary
public InputStreamEntity(final InputStream inStream, final long length, final ContentType contentType)
Parameters
inStream:InputStream

input stream

length:long

of the input stream, -1 if unknown

contentType:ContentType

for specifying the Content-Type header, may be null

Exceptions
IllegalArgumentException:
if inStream is null
Since
4.2

Method Detail

getContentback to summary
public InputStream getContent() throws IOException

Implements org.apache.http.HttpEntity.getContent.

Doc from org.apache.http.HttpEntity.getContent.

Returns a content stream of the entity. Repeatable entities are expected to create a new instance of InputStream for each invocation of this method and therefore can be consumed multiple times. Entities that are not repeatable are expected to return the same InputStream instance and therefore may not be consumed more than once.

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated after the InputStream#close() method is invoked.

Returns:InputStream

content stream of the entity.

Annotations
@Override
Exceptions
IOException:
if the stream could not be created
getContentLengthback to summary
public long getContentLength()

Implements org.apache.http.HttpEntity.getContentLength.

Doc from org.apache.http.HttpEntity.getContentLength.

Tells the length of the content, if known.

Returns:long

the content length or -1 if unknown

Annotations
@Override
isRepeatableback to summary
public boolean isRepeatable()

Implements org.apache.http.HttpEntity.isRepeatable.

Doc from org.apache.http.HttpEntity.isRepeatable.

Tells if the entity is capable of producing its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.

Returns:boolean

true if the entity is repeatable, false otherwise.

Annotations
@Override
isStreamingback to summary
public boolean isStreaming()

Implements org.apache.http.HttpEntity.isStreaming.

Doc from org.apache.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream. Streamed entities that read data directly from the socket should return true. Self-contained entities should return false. Wrapping entities should delegate this call to the wrapped entity.

Returns:boolean

true if the entity content is streamed, false otherwise

Annotations
@Override
writeToback to summary
public void writeTo(final OutputStream outStream) throws IOException

Implements org.apache.http.HttpEntity.writeTo.

Writes bytes from the InputStream this entity was constructed with to an OutputStream. The content length determines how many bytes are written. If the length is unknown (-1), the stream will be completely consumed (to the end of the stream).

Parameters
outStream:OutputStream

Doc from org.apache.http.HttpEntity.writeTo.

the output stream to write entity content to

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.http.HttpEntity.writeTo.

if an I/O error occurs