1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/entity/AbstractHttpEntity.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,182 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.entity; 1.32 + 1.33 +import java.io.IOException; 1.34 +import java.io.OutputStream; 1.35 + 1.36 +import ch.boye.httpclientandroidlib.Header; 1.37 +import ch.boye.httpclientandroidlib.HttpEntity; 1.38 +import ch.boye.httpclientandroidlib.message.BasicHeader; 1.39 +import ch.boye.httpclientandroidlib.protocol.HTTP; 1.40 + 1.41 +/** 1.42 + * Abstract base class for entities. 1.43 + * Provides the commonly used attributes for streamed and self-contained 1.44 + * implementations of {@link HttpEntity HttpEntity}. 1.45 + * 1.46 + * @since 4.0 1.47 + */ 1.48 +public abstract class AbstractHttpEntity implements HttpEntity { 1.49 + 1.50 + protected Header contentType; 1.51 + protected Header contentEncoding; 1.52 + protected boolean chunked; 1.53 + 1.54 + /** 1.55 + * Protected default constructor. 1.56 + * The contentType, contentEncoding and chunked attributes of the created object are set to 1.57 + * <code>null</code>, <code>null</code> and <code>false</code>, respectively. 1.58 + */ 1.59 + protected AbstractHttpEntity() { 1.60 + super(); 1.61 + } 1.62 + 1.63 + 1.64 + /** 1.65 + * Obtains the Content-Type header. 1.66 + * The default implementation returns the value of the 1.67 + * {@link #contentType contentType} attribute. 1.68 + * 1.69 + * @return the Content-Type header, or <code>null</code> 1.70 + */ 1.71 + public Header getContentType() { 1.72 + return this.contentType; 1.73 + } 1.74 + 1.75 + 1.76 + /** 1.77 + * Obtains the Content-Encoding header. 1.78 + * The default implementation returns the value of the 1.79 + * {@link #contentEncoding contentEncoding} attribute. 1.80 + * 1.81 + * @return the Content-Encoding header, or <code>null</code> 1.82 + */ 1.83 + public Header getContentEncoding() { 1.84 + return this.contentEncoding; 1.85 + } 1.86 + 1.87 + /** 1.88 + * Obtains the 'chunked' flag. 1.89 + * The default implementation returns the value of the 1.90 + * {@link #chunked chunked} attribute. 1.91 + * 1.92 + * @return the 'chunked' flag 1.93 + */ 1.94 + public boolean isChunked() { 1.95 + return this.chunked; 1.96 + } 1.97 + 1.98 + 1.99 + /** 1.100 + * Specifies the Content-Type header. 1.101 + * The default implementation sets the value of the 1.102 + * {@link #contentType contentType} attribute. 1.103 + * 1.104 + * @param contentType the new Content-Encoding header, or 1.105 + * <code>null</code> to unset 1.106 + */ 1.107 + public void setContentType(final Header contentType) { 1.108 + this.contentType = contentType; 1.109 + } 1.110 + 1.111 + /** 1.112 + * Specifies the Content-Type header, as a string. 1.113 + * The default implementation calls 1.114 + * {@link #setContentType(Header) setContentType(Header)}. 1.115 + * 1.116 + * @param ctString the new Content-Type header, or 1.117 + * <code>null</code> to unset 1.118 + */ 1.119 + public void setContentType(final String ctString) { 1.120 + Header h = null; 1.121 + if (ctString != null) { 1.122 + h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); 1.123 + } 1.124 + setContentType(h); 1.125 + } 1.126 + 1.127 + 1.128 + /** 1.129 + * Specifies the Content-Encoding header. 1.130 + * The default implementation sets the value of the 1.131 + * {@link #contentEncoding contentEncoding} attribute. 1.132 + * 1.133 + * @param contentEncoding the new Content-Encoding header, or 1.134 + * <code>null</code> to unset 1.135 + */ 1.136 + public void setContentEncoding(final Header contentEncoding) { 1.137 + this.contentEncoding = contentEncoding; 1.138 + } 1.139 + 1.140 + /** 1.141 + * Specifies the Content-Encoding header, as a string. 1.142 + * The default implementation calls 1.143 + * {@link #setContentEncoding(Header) setContentEncoding(Header)}. 1.144 + * 1.145 + * @param ceString the new Content-Encoding header, or 1.146 + * <code>null</code> to unset 1.147 + */ 1.148 + public void setContentEncoding(final String ceString) { 1.149 + Header h = null; 1.150 + if (ceString != null) { 1.151 + h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString); 1.152 + } 1.153 + setContentEncoding(h); 1.154 + } 1.155 + 1.156 + 1.157 + /** 1.158 + * Specifies the 'chunked' flag. 1.159 + * <p> 1.160 + * Note that the chunked setting is a hint only. 1.161 + * If using HTTP/1.0, chunking is never performed. 1.162 + * Otherwise, even if chunked is false, HttpClient must 1.163 + * use chunk coding if the entity content length is 1.164 + * unknown (-1). 1.165 + * <p> 1.166 + * The default implementation sets the value of the 1.167 + * {@link #chunked chunked} attribute. 1.168 + * 1.169 + * @param b the new 'chunked' flag 1.170 + */ 1.171 + public void setChunked(boolean b) { 1.172 + this.chunked = b; 1.173 + } 1.174 + 1.175 + 1.176 + /** 1.177 + * The default implementation does not consume anything. 1.178 + * 1.179 + * @deprecated Either use {@link #getContent()} and call {@link java.io.InputStream#close()} on that; 1.180 + * otherwise call {@link #writeTo(OutputStream)} which is required to free the resources. 1.181 + */ 1.182 + public void consumeContent() throws IOException { 1.183 + } 1.184 + 1.185 +}