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

public Class BasicHttpEntity

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

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

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
BasicHttpEntity()

Creates a new basic entity.

Method Summary

Modifier and TypeMethod and Description
public InputStream

Returns:

the content, if this is the first call to this method since setContent has been called
getContent
()

Implements org.apache.http.HttpEntity.getContent.

Obtains the content, once only.
public long
getContentLength()

Implements org.apache.http.HttpEntity.getContentLength.

Tells the length of the content, if known.
public boolean

Returns:

false
isRepeatable
()

Implements org.apache.http.HttpEntity.isRepeatable.

Tells that this entity is not repeatable.
public boolean
isStreaming()

Implements org.apache.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream.
public void
setContent(final InputStream
the stream to return with the next call to getContent
inStream
)

Specifies the content.

public void
setContentLength(final long
the number of bytes in the content, or a negative number to indicate an unknown length
len
)

Specifies the length of the content.

public void
writeTo(final OutputStream
the output stream to write entity content to
outStream
)

Implements org.apache.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.
Inherited from org.apache.http.entity.AbstractHttpEntity:
consumeContentgetContentEncodinggetContentTypeisChunkedsetChunkedsetContentEncodingsetContentEncodingsetContentTypesetContentTypetoString

Field Detail

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

Constructor Detail

BasicHttpEntityback to summary
public BasicHttpEntity()

Creates a new basic entity. The content is initially missing, the content length is set to a negative number.

Method Detail

getContentback to summary
public InputStream getContent() throws IllegalStateException

Implements org.apache.http.HttpEntity.getContent.

Obtains the content, once only.

Returns:InputStream

the content, if this is the first call to this method since setContent has been called

Annotations
@Override
Exceptions
IllegalStateException:
if the content has not been provided
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 number of bytes of the content, or a negative number if unknown. If the content length is known but exceeds Long.MAX_VALUE, a negative number is returned.

Annotations
@Override
isRepeatableback to summary
public boolean isRepeatable()

Implements org.apache.http.HttpEntity.isRepeatable.

Tells that this entity is not repeatable.

Returns:boolean

false

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
setContentback to summary
public void setContent(final InputStream inStream)

Specifies the content.

Parameters
inStream:InputStream

the stream to return with the next call to getContent

setContentLengthback to summary
public void setContentLength(final long len)

Specifies the length of the content.

Parameters
len:long

the number of bytes in the content, or a negative number to indicate an unknown length

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

Implements org.apache.http.HttpEntity.writeTo.

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

Writes the entity content out to the output stream.

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated when this method returns.

Parameters
outStream:OutputStream

the output stream to write entity content to

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs