Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
28 package ch.boye.httpclientandroidlib.entity;
30 import java.io.IOException;
31 import java.io.OutputStream;
33 import ch.boye.httpclientandroidlib.Header;
34 import ch.boye.httpclientandroidlib.HttpEntity;
35 import ch.boye.httpclientandroidlib.message.BasicHeader;
36 import ch.boye.httpclientandroidlib.protocol.HTTP;
38 /**
39 * Abstract base class for entities.
40 * Provides the commonly used attributes for streamed and self-contained
41 * implementations of {@link HttpEntity HttpEntity}.
42 *
43 * @since 4.0
44 */
45 public abstract class AbstractHttpEntity implements HttpEntity {
47 protected Header contentType;
48 protected Header contentEncoding;
49 protected boolean chunked;
51 /**
52 * Protected default constructor.
53 * The contentType, contentEncoding and chunked attributes of the created object are set to
54 * <code>null</code>, <code>null</code> and <code>false</code>, respectively.
55 */
56 protected AbstractHttpEntity() {
57 super();
58 }
61 /**
62 * Obtains the Content-Type header.
63 * The default implementation returns the value of the
64 * {@link #contentType contentType} attribute.
65 *
66 * @return the Content-Type header, or <code>null</code>
67 */
68 public Header getContentType() {
69 return this.contentType;
70 }
73 /**
74 * Obtains the Content-Encoding header.
75 * The default implementation returns the value of the
76 * {@link #contentEncoding contentEncoding} attribute.
77 *
78 * @return the Content-Encoding header, or <code>null</code>
79 */
80 public Header getContentEncoding() {
81 return this.contentEncoding;
82 }
84 /**
85 * Obtains the 'chunked' flag.
86 * The default implementation returns the value of the
87 * {@link #chunked chunked} attribute.
88 *
89 * @return the 'chunked' flag
90 */
91 public boolean isChunked() {
92 return this.chunked;
93 }
96 /**
97 * Specifies the Content-Type header.
98 * The default implementation sets the value of the
99 * {@link #contentType contentType} attribute.
100 *
101 * @param contentType the new Content-Encoding header, or
102 * <code>null</code> to unset
103 */
104 public void setContentType(final Header contentType) {
105 this.contentType = contentType;
106 }
108 /**
109 * Specifies the Content-Type header, as a string.
110 * The default implementation calls
111 * {@link #setContentType(Header) setContentType(Header)}.
112 *
113 * @param ctString the new Content-Type header, or
114 * <code>null</code> to unset
115 */
116 public void setContentType(final String ctString) {
117 Header h = null;
118 if (ctString != null) {
119 h = new BasicHeader(HTTP.CONTENT_TYPE, ctString);
120 }
121 setContentType(h);
122 }
125 /**
126 * Specifies the Content-Encoding header.
127 * The default implementation sets the value of the
128 * {@link #contentEncoding contentEncoding} attribute.
129 *
130 * @param contentEncoding the new Content-Encoding header, or
131 * <code>null</code> to unset
132 */
133 public void setContentEncoding(final Header contentEncoding) {
134 this.contentEncoding = contentEncoding;
135 }
137 /**
138 * Specifies the Content-Encoding header, as a string.
139 * The default implementation calls
140 * {@link #setContentEncoding(Header) setContentEncoding(Header)}.
141 *
142 * @param ceString the new Content-Encoding header, or
143 * <code>null</code> to unset
144 */
145 public void setContentEncoding(final String ceString) {
146 Header h = null;
147 if (ceString != null) {
148 h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString);
149 }
150 setContentEncoding(h);
151 }
154 /**
155 * Specifies the 'chunked' flag.
156 * <p>
157 * Note that the chunked setting is a hint only.
158 * If using HTTP/1.0, chunking is never performed.
159 * Otherwise, even if chunked is false, HttpClient must
160 * use chunk coding if the entity content length is
161 * unknown (-1).
162 * <p>
163 * The default implementation sets the value of the
164 * {@link #chunked chunked} attribute.
165 *
166 * @param b the new 'chunked' flag
167 */
168 public void setChunked(boolean b) {
169 this.chunked = b;
170 }
173 /**
174 * The default implementation does not consume anything.
175 *
176 * @deprecated Either use {@link #getContent()} and call {@link java.io.InputStream#close()} on that;
177 * otherwise call {@link #writeTo(OutputStream)} which is required to free the resources.
178 */
179 public void consumeContent() throws IOException {
180 }
182 }