mobile/android/thirdparty/ch/boye/httpclientandroidlib/HttpEntity.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/HttpEntity.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,198 @@
     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;
    1.32 +
    1.33 +import java.io.IOException;
    1.34 +import java.io.InputStream;
    1.35 +import java.io.OutputStream;
    1.36 +
    1.37 +/**
    1.38 + * An entity that can be sent or received with an HTTP message.
    1.39 + * Entities can be found in some
    1.40 + * {@link HttpEntityEnclosingRequest requests} and in
    1.41 + * {@link HttpResponse responses}, where they are optional.
    1.42 + * <p>
    1.43 + * There are three distinct types of entities in HttpCore,
    1.44 + * depending on where their {@link #getContent content} originates:
    1.45 + * <ul>
    1.46 + * <li><b>streamed</b>: The content is received from a stream, or
    1.47 + *     generated on the fly. In particular, this category includes
    1.48 + *     entities being received from a {@link HttpConnection connection}.
    1.49 + *     {@link #isStreaming Streamed} entities are generally not
    1.50 + *      {@link #isRepeatable repeatable}.
    1.51 + *     </li>
    1.52 + * <li><b>self-contained</b>: The content is in memory or obtained by
    1.53 + *     means that are independent from a connection or other entity.
    1.54 + *     Self-contained entities are generally {@link #isRepeatable repeatable}.
    1.55 + *     </li>
    1.56 + * <li><b>wrapping</b>: The content is obtained from another entity.
    1.57 + *     </li>
    1.58 + * </ul>
    1.59 + * This distinction is important for connection management with incoming
    1.60 + * entities. For entities that are created by an application and only sent
    1.61 + * using the HTTP components framework, the difference between streamed
    1.62 + * and self-contained is of little importance. In that case, it is suggested
    1.63 + * to consider non-repeatable entities as streamed, and those that are
    1.64 + * repeatable (without a huge effort) as self-contained.
    1.65 + *
    1.66 + * @since 4.0
    1.67 + */
    1.68 +public interface HttpEntity {
    1.69 +
    1.70 +    /**
    1.71 +     * Tells if the entity is capable of producing its data more than once.
    1.72 +     * A repeatable entity's getContent() and writeTo(OutputStream) methods
    1.73 +     * can be called more than once whereas a non-repeatable entity's can not.
    1.74 +     * @return true if the entity is repeatable, false otherwise.
    1.75 +     */
    1.76 +    boolean isRepeatable();
    1.77 +
    1.78 +    /**
    1.79 +     * Tells about chunked encoding for this entity.
    1.80 +     * The primary purpose of this method is to indicate whether
    1.81 +     * chunked encoding should be used when the entity is sent.
    1.82 +     * For entities that are received, it can also indicate whether
    1.83 +     * the entity was received with chunked encoding.
    1.84 +     * <br/>
    1.85 +     * The behavior of wrapping entities is implementation dependent,
    1.86 +     * but should respect the primary purpose.
    1.87 +     *
    1.88 +     * @return  <code>true</code> if chunked encoding is preferred for this
    1.89 +     *          entity, or <code>false</code> if it is not
    1.90 +     */
    1.91 +    boolean isChunked();
    1.92 +
    1.93 +    /**
    1.94 +     * Tells the length of the content, if known.
    1.95 +     *
    1.96 +     * @return  the number of bytes of the content, or
    1.97 +     *          a negative number if unknown. If the content length is known
    1.98 +     *          but exceeds {@link java.lang.Long#MAX_VALUE Long.MAX_VALUE},
    1.99 +     *          a negative number is returned.
   1.100 +     */
   1.101 +    long getContentLength();
   1.102 +
   1.103 +    /**
   1.104 +     * Obtains the Content-Type header, if known.
   1.105 +     * This is the header that should be used when sending the entity,
   1.106 +     * or the one that was received with the entity. It can include a
   1.107 +     * charset attribute.
   1.108 +     *
   1.109 +     * @return  the Content-Type header for this entity, or
   1.110 +     *          <code>null</code> if the content type is unknown
   1.111 +     */
   1.112 +    Header getContentType();
   1.113 +
   1.114 +    /**
   1.115 +     * Obtains the Content-Encoding header, if known.
   1.116 +     * This is the header that should be used when sending the entity,
   1.117 +     * or the one that was received with the entity.
   1.118 +     * Wrapping entities that modify the content encoding should
   1.119 +     * adjust this header accordingly.
   1.120 +     *
   1.121 +     * @return  the Content-Encoding header for this entity, or
   1.122 +     *          <code>null</code> if the content encoding is unknown
   1.123 +     */
   1.124 +    Header getContentEncoding();
   1.125 +
   1.126 +    /**
   1.127 +     * Returns a content stream of the entity.
   1.128 +     * {@link #isRepeatable Repeatable} entities are expected
   1.129 +     * to create a new instance of {@link InputStream} for each invocation
   1.130 +     * of this method and therefore can be consumed multiple times.
   1.131 +     * Entities that are not {@link #isRepeatable repeatable} are expected
   1.132 +     * to return the same {@link InputStream} instance and therefore
   1.133 +     * may not be consumed more than once.
   1.134 +     * <p>
   1.135 +     * IMPORTANT: Please note all entity implementations must ensure that
   1.136 +     * all allocated resources are properly deallocated after
   1.137 +     * the {@link InputStream#close()} method is invoked.
   1.138 +     *
   1.139 +     * @return content stream of the entity.
   1.140 +     *
   1.141 +     * @throws IOException if the stream could not be created
   1.142 +     * @throws IllegalStateException
   1.143 +     *  if content stream cannot be created.
   1.144 +     *
   1.145 +     * @see #isRepeatable()
   1.146 +     */
   1.147 +    InputStream getContent() throws IOException, IllegalStateException;
   1.148 +
   1.149 +    /**
   1.150 +     * Writes the entity content out to the output stream.
   1.151 +     * <p>
   1.152 +     * <p>
   1.153 +     * IMPORTANT: Please note all entity implementations must ensure that
   1.154 +     * all allocated resources are properly deallocated when this method
   1.155 +     * returns.
   1.156 +     *
   1.157 +     * @param outstream the output stream to write entity content to
   1.158 +     *
   1.159 +     * @throws IOException if an I/O error occurs
   1.160 +     */
   1.161 +    void writeTo(OutputStream outstream) throws IOException;
   1.162 +
   1.163 +    /**
   1.164 +     * Tells whether this entity depends on an underlying stream.
   1.165 +     * Streamed entities that read data directly from the socket should
   1.166 +     * return <code>true</code>. Self-contained entities should return
   1.167 +     * <code>false</code>. Wrapping entities should delegate this call
   1.168 +     * to the wrapped entity.
   1.169 +     *
   1.170 +     * @return  <code>true</code> if the entity content is streamed,
   1.171 +     *          <code>false</code> otherwise
   1.172 +     */
   1.173 +    boolean isStreaming(); // don't expect an exception here
   1.174 +
   1.175 +    /**
   1.176 +     * This method is deprecated since version 4.1. Please use standard
   1.177 +     * java convention to ensure resource deallocation by calling
   1.178 +     * {@link InputStream#close()} on the input stream returned by
   1.179 +     * {@link #getContent()}
   1.180 +     * <p>
   1.181 +     * This method is called to indicate that the content of this entity
   1.182 +     * is no longer required. All entity implementations are expected to
   1.183 +     * release all allocated resources as a result of this method
   1.184 +     * invocation. Content streaming entities are also expected to
   1.185 +     * dispose of the remaining content, if any. Wrapping entities should
   1.186 +     * delegate this call to the wrapped entity.
   1.187 +     * <p>
   1.188 +     * This method is of particular importance for entities being
   1.189 +     * received from a {@link HttpConnection connection}. The entity
   1.190 +     * needs to be consumed completely in order to re-use the connection
   1.191 +     * with keep-alive.
   1.192 +     *
   1.193 +     * @throws IOException if an I/O error occurs.
   1.194 +     *
   1.195 +     * @deprecated Use {@link ch.boye.httpclientandroidlib.util.EntityUtils#consume(HttpEntity)}
   1.196 +     *
   1.197 +     * @see #getContent() and #writeTo(OutputStream)
   1.198 +     */
   1.199 +    void consumeContent() throws IOException;
   1.200 +
   1.201 +}

mercurial