1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/*
2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/AbstractHttpEntity.java $
3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 496070 $
4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2007-01-14 04:18:34 -0800 (Sun, 14 Jan 2007) $
5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Licensed to the Apache Software Foundation (ASF) under one
8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * or more contributor license agreements.  See the NOTICE file
9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * distributed with this work for additional information
10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * regarding copyright ownership.  The ASF licenses this file
11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to you under the Apache License, Version 2.0 (the
12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * "License"); you may not use this file except in compliance
13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * with the License.  You may obtain a copy of the License at
14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   http://www.apache.org/licenses/LICENSE-2.0
16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Unless required by applicable law or agreed to in writing,
18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * software distributed under the License is distributed on an
19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * KIND, either express or implied.  See the License for the
21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * specific language governing permissions and limitations
22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * under the License.
23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This software consists of voluntary contributions made by many
26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * individuals on behalf of the Apache Software Foundation.  For more
27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * information on the Apache Software Foundation, please see
28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <http://www.apache.org/>.
29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpackage org.apache.http.entity;
33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.io.IOException;
35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.Header;
37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.HttpEntity;
38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.message.BasicHeader;
39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.protocol.HTTP;
40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/**
42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Abstract base class for entities.
43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Provides the commonly used attributes for streamed and self-contained
44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * implementations of {@link HttpEntity HttpEntity}.
45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @version $Revision: 496070 $
49069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @since 4.0
51d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *
52d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * @deprecated Please use {@link java.net.URL#openConnection} instead.
53d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
54d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *     for further details.
55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
56d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath@Deprecated
57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic abstract class AbstractHttpEntity implements HttpEntity {
58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The Content-Type header.
61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Returned by {@link #getContentType getContentType},
62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * unless that method is overridden.
63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    protected Header contentType;
65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The Content-Encoding header.
68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Returned by {@link #getContentEncoding getContentEncoding},
69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * unless that method is overridden.
70069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
71069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    protected Header contentEncoding;
72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
73069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The 'chunked' flag.
75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Returned by {@link #isChunked isChunked},
76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * unless that method is overridden.
77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    protected boolean chunked;
79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Protected default constructor.
83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The attributes of the created object remain
84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * <code>null</code> and <code>false</code>, respectively.
85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    protected AbstractHttpEntity() {
87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        super();
88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Obtains the Content-Type header.
93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation returns the value of the
94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #contentType contentType} attribute.
95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return  the Content-Type header, or <code>null</code>
97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public Header getContentType() {
99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return this.contentType;
100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Obtains the Content-Encoding header.
105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation returns the value of the
106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #contentEncoding contentEncoding} attribute.
107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return  the Content-Encoding header, or <code>null</code>
109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public Header getContentEncoding() {
111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return this.contentEncoding;
112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Obtains the 'chunked' flag.
116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation returns the value of the
117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #chunked chunked} attribute.
118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return  the 'chunked' flag
120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public boolean isChunked() {
122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return this.chunked;
123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Specifies the Content-Type header.
128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation sets the value of the
129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #contentType contentType} attribute.
130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param contentType       the new Content-Encoding header, or
132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                          <code>null</code> to unset
133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void setContentType(final Header contentType) {
135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        this.contentType = contentType;
136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Specifies the Content-Type header, as a string.
140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation calls
141069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #setContentType(Header) setContentType(Header)}.
142069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
143069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param ctString     the new Content-Type header, or
144069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                     <code>null</code> to unset
145069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
146069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void setContentType(final String ctString) {
147069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        Header h = null;
148069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (ctString != null) {
149069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            h = new BasicHeader(HTTP.CONTENT_TYPE, ctString);
150069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
151069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        setContentType(h);
152069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
153069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
154069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
155069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
156069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Specifies the Content-Encoding header.
157069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation sets the value of the
158069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #contentEncoding contentEncoding} attribute.
159069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
160069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param contentEncoding   the new Content-Encoding header, or
161069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                          <code>null</code> to unset
162069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
163069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void setContentEncoding(final Header contentEncoding) {
164069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        this.contentEncoding = contentEncoding;
165069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
166069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
167069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
168069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Specifies the Content-Encoding header, as a string.
169069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation calls
170069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #setContentEncoding(Header) setContentEncoding(Header)}.
171069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
172069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param ceString     the new Content-Encoding header, or
173069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                     <code>null</code> to unset
174069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
175069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void setContentEncoding(final String ceString) {
176069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        Header h = null;
177069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (ceString != null) {
178069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString);
179069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
180069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        setContentEncoding(h);
181069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
182069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
183069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
184069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
185069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Specifies the 'chunked' flag.
186069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation sets the value of the
187069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #chunked chunked} attribute.
188069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
189069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param b         the new 'chunked' flag
190069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
191069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void setChunked(boolean b) {
192069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        this.chunked = b;
193069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
194069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
195069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
196069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
197069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Does not consume anything.
198069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The default implementation does nothing if
199069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link HttpEntity#isStreaming isStreaming}
200069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * returns <code>false</code>, and throws an exception
201069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * if it returns <code>true</code>.
202069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * This removes the burden of implementing
203069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * an empty method for non-streaming entities.
204069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
205069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws IOException      in case of an I/O problem
206069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws UnsupportedOperationException
207069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *          if a streaming subclass does not override this method
208069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
209069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void consumeContent()
210069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        throws IOException, UnsupportedOperationException{
211069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (isStreaming()) {
212069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new UnsupportedOperationException
213069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                ("streaming entity does not implement consumeContent()");
214069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
215069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    } // consumeContent
216069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
217069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
218069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project} // class AbstractHttpEntity
219