2
* $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java $
4
* $Date: 2009-02-14 17:57:41 +0100 (Sat, 14 Feb 2009) $
6
* ====================================================================
7
* Licensed to the Apache Software Foundation (ASF) under one
8
* or more contributor license agreements. See the NOTICE file
9
* distributed with this work for additional information
10
* regarding copyright ownership. The ASF licenses this file
11
* to you under the Apache License, Version 2.0 (the
12
* "License"); you may not use this file except in compliance
13
* with the License. You may obtain a copy of the License at
15
* http://www.apache.org/licenses/LICENSE-2.0
17
* Unless required by applicable law or agreed to in writing,
18
* software distributed under the License is distributed on an
19
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
* KIND, either express or implied. See the License for the
21
* specific language governing permissions and limitations
23
* ====================================================================
25
* This software consists of voluntary contributions made by many
26
* individuals on behalf of the Apache Software Foundation. For more
27
* information on the Apache Software Foundation, please see
28
* <http://www.apache.org/>.
32
package org.apache.http.entity;
34
import java.io.IOException;
36
import org.apache.http.Header;
37
import org.apache.http.HttpEntity;
38
import org.apache.http.message.BasicHeader;
39
import org.apache.http.protocol.HTTP;
42
* Abstract base class for entities.
43
* Provides the commonly used attributes for streamed and self-contained
44
* implementations of {@link HttpEntity HttpEntity}.
47
* @version $Revision: 744523 $
51
public abstract class AbstractHttpEntity implements HttpEntity {
53
protected Header contentType;
54
protected Header contentEncoding;
55
protected boolean chunked;
58
* Protected default constructor.
59
* The attributes of the created object remain
60
* <code>null</code> and <code>false</code>, respectively.
62
protected AbstractHttpEntity() {
68
* Obtains the Content-Type header.
69
* The default implementation returns the value of the
70
* {@link #contentType contentType} attribute.
72
* @return the Content-Type header, or <code>null</code>
74
public Header getContentType() {
75
return this.contentType;
80
* Obtains the Content-Encoding header.
81
* The default implementation returns the value of the
82
* {@link #contentEncoding contentEncoding} attribute.
84
* @return the Content-Encoding header, or <code>null</code>
86
public Header getContentEncoding() {
87
return this.contentEncoding;
91
* Obtains the 'chunked' flag.
92
* The default implementation returns the value of the
93
* {@link #chunked chunked} attribute.
95
* @return the 'chunked' flag
97
public boolean isChunked() {
103
* Specifies the Content-Type header.
104
* The default implementation sets the value of the
105
* {@link #contentType contentType} attribute.
107
* @param contentType the new Content-Encoding header, or
108
* <code>null</code> to unset
110
public void setContentType(final Header contentType) {
111
this.contentType = contentType;
115
* Specifies the Content-Type header, as a string.
116
* The default implementation calls
117
* {@link #setContentType(Header) setContentType(Header)}.
119
* @param ctString the new Content-Type header, or
120
* <code>null</code> to unset
122
public void setContentType(final String ctString) {
124
if (ctString != null) {
125
h = new BasicHeader(HTTP.CONTENT_TYPE, ctString);
132
* Specifies the Content-Encoding header.
133
* The default implementation sets the value of the
134
* {@link #contentEncoding contentEncoding} attribute.
136
* @param contentEncoding the new Content-Encoding header, or
137
* <code>null</code> to unset
139
public void setContentEncoding(final Header contentEncoding) {
140
this.contentEncoding = contentEncoding;
144
* Specifies the Content-Encoding header, as a string.
145
* The default implementation calls
146
* {@link #setContentEncoding(Header) setContentEncoding(Header)}.
148
* @param ceString the new Content-Encoding header, or
149
* <code>null</code> to unset
151
public void setContentEncoding(final String ceString) {
153
if (ceString != null) {
154
h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString);
156
setContentEncoding(h);
161
* Specifies the 'chunked' flag.
162
* The default implementation sets the value of the
163
* {@link #chunked chunked} attribute.
165
* @param b the new 'chunked' flag
167
public void setChunked(boolean b) {
173
* Does not consume anything.
174
* The default implementation does nothing if
175
* {@link HttpEntity#isStreaming isStreaming}
176
* returns <code>false</code>, and throws an exception
177
* if it returns <code>true</code>.
178
* This removes the burden of implementing
179
* an empty method for non-streaming entities.
181
* @throws IOException in case of an I/O problem
182
* @throws UnsupportedOperationException
183
* if a streaming subclass does not override this method
185
public void consumeContent()
186
throws IOException, UnsupportedOperationException{
188
throw new UnsupportedOperationException
189
("streaming entity does not implement consumeContent()");
194
} // class AbstractHttpEntity