michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.entity; michael@0: michael@0: import java.io.IOException; michael@0: import java.io.OutputStream; michael@0: michael@0: import ch.boye.httpclientandroidlib.Header; michael@0: import ch.boye.httpclientandroidlib.HttpEntity; michael@0: import ch.boye.httpclientandroidlib.message.BasicHeader; michael@0: import ch.boye.httpclientandroidlib.protocol.HTTP; michael@0: michael@0: /** michael@0: * Abstract base class for entities. michael@0: * Provides the commonly used attributes for streamed and self-contained michael@0: * implementations of {@link HttpEntity HttpEntity}. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public abstract class AbstractHttpEntity implements HttpEntity { michael@0: michael@0: protected Header contentType; michael@0: protected Header contentEncoding; michael@0: protected boolean chunked; michael@0: michael@0: /** michael@0: * Protected default constructor. michael@0: * The contentType, contentEncoding and chunked attributes of the created object are set to michael@0: * null, null and false, respectively. michael@0: */ michael@0: protected AbstractHttpEntity() { michael@0: super(); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Obtains the Content-Type header. michael@0: * The default implementation returns the value of the michael@0: * {@link #contentType contentType} attribute. michael@0: * michael@0: * @return the Content-Type header, or null michael@0: */ michael@0: public Header getContentType() { michael@0: return this.contentType; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Obtains the Content-Encoding header. michael@0: * The default implementation returns the value of the michael@0: * {@link #contentEncoding contentEncoding} attribute. michael@0: * michael@0: * @return the Content-Encoding header, or null michael@0: */ michael@0: public Header getContentEncoding() { michael@0: return this.contentEncoding; michael@0: } michael@0: michael@0: /** michael@0: * Obtains the 'chunked' flag. michael@0: * The default implementation returns the value of the michael@0: * {@link #chunked chunked} attribute. michael@0: * michael@0: * @return the 'chunked' flag michael@0: */ michael@0: public boolean isChunked() { michael@0: return this.chunked; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Specifies the Content-Type header. michael@0: * The default implementation sets the value of the michael@0: * {@link #contentType contentType} attribute. michael@0: * michael@0: * @param contentType the new Content-Encoding header, or michael@0: * null to unset michael@0: */ michael@0: public void setContentType(final Header contentType) { michael@0: this.contentType = contentType; michael@0: } michael@0: michael@0: /** michael@0: * Specifies the Content-Type header, as a string. michael@0: * The default implementation calls michael@0: * {@link #setContentType(Header) setContentType(Header)}. michael@0: * michael@0: * @param ctString the new Content-Type header, or michael@0: * null to unset michael@0: */ michael@0: public void setContentType(final String ctString) { michael@0: Header h = null; michael@0: if (ctString != null) { michael@0: h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); michael@0: } michael@0: setContentType(h); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Specifies the Content-Encoding header. michael@0: * The default implementation sets the value of the michael@0: * {@link #contentEncoding contentEncoding} attribute. michael@0: * michael@0: * @param contentEncoding the new Content-Encoding header, or michael@0: * null to unset michael@0: */ michael@0: public void setContentEncoding(final Header contentEncoding) { michael@0: this.contentEncoding = contentEncoding; michael@0: } michael@0: michael@0: /** michael@0: * Specifies the Content-Encoding header, as a string. michael@0: * The default implementation calls michael@0: * {@link #setContentEncoding(Header) setContentEncoding(Header)}. michael@0: * michael@0: * @param ceString the new Content-Encoding header, or michael@0: * null to unset michael@0: */ michael@0: public void setContentEncoding(final String ceString) { michael@0: Header h = null; michael@0: if (ceString != null) { michael@0: h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString); michael@0: } michael@0: setContentEncoding(h); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Specifies the 'chunked' flag. michael@0: *

michael@0: * Note that the chunked setting is a hint only. michael@0: * If using HTTP/1.0, chunking is never performed. michael@0: * Otherwise, even if chunked is false, HttpClient must michael@0: * use chunk coding if the entity content length is michael@0: * unknown (-1). michael@0: *

michael@0: * The default implementation sets the value of the michael@0: * {@link #chunked chunked} attribute. michael@0: * michael@0: * @param b the new 'chunked' flag michael@0: */ michael@0: public void setChunked(boolean b) { michael@0: this.chunked = b; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * The default implementation does not consume anything. michael@0: * michael@0: * @deprecated Either use {@link #getContent()} and call {@link java.io.InputStream#close()} on that; michael@0: * otherwise call {@link #writeTo(OutputStream)} which is required to free the resources. michael@0: */ michael@0: public void consumeContent() throws IOException { michael@0: } michael@0: michael@0: }