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

EntityDeserializer

public class EntityDeserializer extends Object
Default implementation of an entity deserializer.

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

author
Oleg Kalnichevski
version
$Revision: 560358 $
since
4.0

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

        super();
        if (lenStrategy == null) {
            throw new IllegalArgumentException("Content length strategy may not be null");
        }
        this.lenStrategy = lenStrategy;
    
Methods Summary
public org.apache.http.HttpEntitydeserialize(org.apache.http.io.SessionInputBuffer inbuffer, org.apache.http.HttpMessage message)

        if (inbuffer == null) {
            throw new IllegalArgumentException("Session input buffer may not be null");
        }
        if (message == null) {
            throw new IllegalArgumentException("HTTP message may not be null");
        }
        return doDeserialize(inbuffer, message);
    
protected org.apache.http.entity.BasicHttpEntitydoDeserialize(org.apache.http.io.SessionInputBuffer inbuffer, org.apache.http.HttpMessage message)

        BasicHttpEntity entity = new BasicHttpEntity();
        
        long len = this.lenStrategy.determineLength(message);
        if (len == ContentLengthStrategy.CHUNKED) {
            entity.setChunked(true);
            entity.setContentLength(-1);
            entity.setContent(new ChunkedInputStream(inbuffer));
        } else if (len == ContentLengthStrategy.IDENTITY) {
            entity.setChunked(false);
            entity.setContentLength(-1);
            entity.setContent(new IdentityInputStream(inbuffer));                            
        } else {
            entity.setChunked(false);
            entity.setContentLength(len);
            entity.setContent(new ContentLengthInputStream(inbuffer, len));
        }
        
        Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
        if (contentTypeHeader != null) {
            entity.setContentType(contentTypeHeader);    
        }
        Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
        if (contentEncodingHeader != null) {
            entity.setContentEncoding(contentEncodingHeader);    
        }
        return entity;