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

public Class SerializableEntity

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

A streamed entity that obtains its content from a Serializable. The content obtained from the Serializable instance can optionally be buffered in a byte array in order to make the entity self-contained and repeatable.
Since
4.0

Field Summary

Modifier and TypeField and Description
private Serializable
private byte[]
Inherited from org.apache.http.entity.AbstractHttpEntity:
chunkedcontentEncodingcontentTypeOUTPUT_BUFFER_SIZE

Constructor Summary

AccessConstructor and Description
public
SerializableEntity(final Serializable
input
ser
,
final boolean
tells whether the content should be stored in an internal buffer
bufferize
)

Creates new instance of this class.

public
SerializableEntity(final Serializable
The object to serialize.
serializable
)

Creates new instance of this class.

Method Summary

Modifier and TypeMethod and Description
private void
public InputStream
getContent()

Implements org.apache.http.HttpEntity.getContent.

Returns a content stream of the entity.
public long
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 the entity content out to the output stream.
Inherited from org.apache.http.entity.AbstractHttpEntity:
consumeContentgetContentEncodinggetContentTypeisChunkedsetChunkedsetContentEncodingsetContentEncodingsetContentTypesetContentTypetoString

Field Detail

objRefback to summary
private Serializable objRef
objSerback to summary
private byte[] objSer

Constructor Detail

SerializableEntityback to summary
public SerializableEntity(final Serializable ser, final boolean bufferize) throws IOException

Creates new instance of this class.

Parameters
ser:Serializable

input

bufferize:boolean

tells whether the content should be stored in an internal buffer

Exceptions
IOException:
in case of an I/O error
SerializableEntityback to summary
public SerializableEntity(final Serializable serializable)

Creates new instance of this class.

Parameters
serializable:Serializable

The object to serialize.

Since
4.3

Method Detail

createBytesback to summary
private void createBytes(final Serializable ser) throws IOException
getContentback to summary
public InputStream getContent() throws IOException, IllegalStateException

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 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.

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.

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