FileDocCategorySizeDatePackage
EntitySerializer.javaAPI DocAndroid 1.5 API3795Wed May 06 22:41:10 BST 2009org.apache.http.impl.entity

EntitySerializer

public class EntitySerializer extends Object
Default implementation of an entity serializer.

This entity serializer currently supports only "chunked" and "identitiy" transfer-coding

author
Oleg Kalnichevski
version
$Revision: 560343 $
since
4.0

Fields Summary
private final ContentLengthStrategy
lenStrategy
Constructors Summary
public EntitySerializer(ContentLengthStrategy lenStrategy)

        super();
        if (lenStrategy == null) {
            throw new IllegalArgumentException("Content length strategy may not be null");
        }
        this.lenStrategy = lenStrategy;
    
Methods Summary
protected java.io.OutputStreamdoSerialize(org.apache.http.io.SessionOutputBuffer outbuffer, org.apache.http.HttpMessage message)

        long len = this.lenStrategy.determineLength(message);
        if (len == ContentLengthStrategy.CHUNKED) {
            return new ChunkedOutputStream(outbuffer);
        } else if (len == ContentLengthStrategy.IDENTITY) {
            return new IdentityOutputStream(outbuffer);
        } else {
            return new ContentLengthOutputStream(outbuffer, len);
        }
    
public voidserialize(org.apache.http.io.SessionOutputBuffer outbuffer, org.apache.http.HttpMessage message, org.apache.http.HttpEntity entity)

        if (outbuffer == null) {
            throw new IllegalArgumentException("Session output buffer may not be null");
        }
        if (message == null) {
            throw new IllegalArgumentException("HTTP message may not be null");
        }
        if (entity == null) {
            throw new IllegalArgumentException("HTTP entity may not be null");
        }
        OutputStream outstream = doSerialize(outbuffer, message);
        entity.writeTo(outstream);
        outstream.close();