~ubuntu-branches/ubuntu/trusty/httpcomponents-core/trusty

« back to all changes in this revision

Viewing changes to httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-06-12 08:37:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100612083734-1y8kp6qm4sjk60az
Tags: upstream-4.0.1
ImportĀ upstreamĀ versionĀ 4.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java $
 
3
 * $Revision: 744523 $
 
4
 * $Date: 2009-02-14 17:57:41 +0100 (Sat, 14 Feb 2009) $
 
5
 *
 
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
 
14
 *
 
15
 *   http://www.apache.org/licenses/LICENSE-2.0
 
16
 *
 
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
 
22
 * under the License.
 
23
 * ====================================================================
 
24
 *
 
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/>.
 
29
 *
 
30
 */
 
31
 
 
32
package org.apache.http.entity;
 
33
 
 
34
import java.io.IOException;
 
35
 
 
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;
 
40
 
 
41
/**
 
42
 * Abstract base class for entities.
 
43
 * Provides the commonly used attributes for streamed and self-contained
 
44
 * implementations of {@link HttpEntity HttpEntity}.
 
45
 *
 
46
 *
 
47
 * @version $Revision: 744523 $
 
48
 * 
 
49
 * @since 4.0
 
50
 */
 
51
public abstract class AbstractHttpEntity implements HttpEntity {
 
52
 
 
53
    protected Header contentType;
 
54
    protected Header contentEncoding;
 
55
    protected boolean chunked;
 
56
 
 
57
    /**
 
58
     * Protected default constructor.
 
59
     * The attributes of the created object remain
 
60
     * <code>null</code> and <code>false</code>, respectively.
 
61
     */
 
62
    protected AbstractHttpEntity() {
 
63
        super();
 
64
    }
 
65
 
 
66
 
 
67
    /**
 
68
     * Obtains the Content-Type header.
 
69
     * The default implementation returns the value of the
 
70
     * {@link #contentType contentType} attribute.
 
71
     *
 
72
     * @return  the Content-Type header, or <code>null</code>
 
73
     */
 
74
    public Header getContentType() {
 
75
        return this.contentType;
 
76
    }
 
77
 
 
78
    
 
79
    /**
 
80
     * Obtains the Content-Encoding header.
 
81
     * The default implementation returns the value of the
 
82
     * {@link #contentEncoding contentEncoding} attribute.
 
83
     *
 
84
     * @return  the Content-Encoding header, or <code>null</code>
 
85
     */
 
86
    public Header getContentEncoding() {
 
87
        return this.contentEncoding;
 
88
    }
 
89
 
 
90
    /**
 
91
     * Obtains the 'chunked' flag.
 
92
     * The default implementation returns the value of the
 
93
     * {@link #chunked chunked} attribute.
 
94
     *
 
95
     * @return  the 'chunked' flag
 
96
     */
 
97
    public boolean isChunked() {
 
98
        return this.chunked;
 
99
    }
 
100
 
 
101
    
 
102
    /**
 
103
     * Specifies the Content-Type header.
 
104
     * The default implementation sets the value of the
 
105
     * {@link #contentType contentType} attribute.
 
106
     *
 
107
     * @param contentType       the new Content-Encoding header, or
 
108
     *                          <code>null</code> to unset
 
109
     */
 
110
    public void setContentType(final Header contentType) {
 
111
        this.contentType = contentType;
 
112
    }
 
113
 
 
114
    /**
 
115
     * Specifies the Content-Type header, as a string.
 
116
     * The default implementation calls
 
117
     * {@link #setContentType(Header) setContentType(Header)}.
 
118
     *
 
119
     * @param ctString     the new Content-Type header, or
 
120
     *                     <code>null</code> to unset
 
121
     */
 
122
    public void setContentType(final String ctString) {
 
123
        Header h = null;
 
124
        if (ctString != null) {
 
125
            h = new BasicHeader(HTTP.CONTENT_TYPE, ctString);
 
126
        }
 
127
        setContentType(h);
 
128
    }
 
129
    
 
130
 
 
131
    /**
 
132
     * Specifies the Content-Encoding header.
 
133
     * The default implementation sets the value of the
 
134
     * {@link #contentEncoding contentEncoding} attribute.
 
135
     *
 
136
     * @param contentEncoding   the new Content-Encoding header, or
 
137
     *                          <code>null</code> to unset
 
138
     */
 
139
    public void setContentEncoding(final Header contentEncoding) {
 
140
        this.contentEncoding = contentEncoding;
 
141
    }
 
142
 
 
143
    /**
 
144
     * Specifies the Content-Encoding header, as a string.
 
145
     * The default implementation calls
 
146
     * {@link #setContentEncoding(Header) setContentEncoding(Header)}.
 
147
     *
 
148
     * @param ceString     the new Content-Encoding header, or
 
149
     *                     <code>null</code> to unset
 
150
     */
 
151
    public void setContentEncoding(final String ceString) {
 
152
        Header h = null;
 
153
        if (ceString != null) {
 
154
            h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString);
 
155
        }
 
156
        setContentEncoding(h);
 
157
    }
 
158
 
 
159
 
 
160
    /**
 
161
     * Specifies the 'chunked' flag.
 
162
     * The default implementation sets the value of the
 
163
     * {@link #chunked chunked} attribute.
 
164
     *
 
165
     * @param b         the new 'chunked' flag
 
166
     */
 
167
    public void setChunked(boolean b) {
 
168
        this.chunked = b;
 
169
    }
 
170
 
 
171
 
 
172
    /**
 
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.
 
180
     *
 
181
     * @throws IOException      in case of an I/O problem
 
182
     * @throws UnsupportedOperationException
 
183
     *          if a streaming subclass does not override this method
 
184
     */
 
185
    public void consumeContent()
 
186
        throws IOException, UnsupportedOperationException{
 
187
        if (isStreaming()) {
 
188
            throw new UnsupportedOperationException
 
189
                ("streaming entity does not implement consumeContent()");
 
190
        }
 
191
    } // consumeContent
 
192
 
 
193
    
 
194
} // class AbstractHttpEntity