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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 * ====================================================================
michael@0 3 * Licensed to the Apache Software Foundation (ASF) under one
michael@0 4 * or more contributor license agreements. See the NOTICE file
michael@0 5 * distributed with this work for additional information
michael@0 6 * regarding copyright ownership. The ASF licenses this file
michael@0 7 * to you under the Apache License, Version 2.0 (the
michael@0 8 * "License"); you may not use this file except in compliance
michael@0 9 * with the License. You may obtain a copy of the License at
michael@0 10 *
michael@0 11 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 12 *
michael@0 13 * Unless required by applicable law or agreed to in writing,
michael@0 14 * software distributed under the License is distributed on an
michael@0 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0 16 * KIND, either express or implied. See the License for the
michael@0 17 * specific language governing permissions and limitations
michael@0 18 * under the License.
michael@0 19 * ====================================================================
michael@0 20 *
michael@0 21 * This software consists of voluntary contributions made by many
michael@0 22 * individuals on behalf of the Apache Software Foundation. For more
michael@0 23 * information on the Apache Software Foundation, please see
michael@0 24 * <http://www.apache.org/>.
michael@0 25 *
michael@0 26 */
michael@0 27
michael@0 28 package ch.boye.httpclientandroidlib;
michael@0 29
michael@0 30 import java.io.IOException;
michael@0 31 import java.io.InputStream;
michael@0 32 import java.io.OutputStream;
michael@0 33
michael@0 34 /**
michael@0 35 * An entity that can be sent or received with an HTTP message.
michael@0 36 * Entities can be found in some
michael@0 37 * {@link HttpEntityEnclosingRequest requests} and in
michael@0 38 * {@link HttpResponse responses}, where they are optional.
michael@0 39 * <p>
michael@0 40 * There are three distinct types of entities in HttpCore,
michael@0 41 * depending on where their {@link #getContent content} originates:
michael@0 42 * <ul>
michael@0 43 * <li><b>streamed</b>: The content is received from a stream, or
michael@0 44 * generated on the fly. In particular, this category includes
michael@0 45 * entities being received from a {@link HttpConnection connection}.
michael@0 46 * {@link #isStreaming Streamed} entities are generally not
michael@0 47 * {@link #isRepeatable repeatable}.
michael@0 48 * </li>
michael@0 49 * <li><b>self-contained</b>: The content is in memory or obtained by
michael@0 50 * means that are independent from a connection or other entity.
michael@0 51 * Self-contained entities are generally {@link #isRepeatable repeatable}.
michael@0 52 * </li>
michael@0 53 * <li><b>wrapping</b>: The content is obtained from another entity.
michael@0 54 * </li>
michael@0 55 * </ul>
michael@0 56 * This distinction is important for connection management with incoming
michael@0 57 * entities. For entities that are created by an application and only sent
michael@0 58 * using the HTTP components framework, the difference between streamed
michael@0 59 * and self-contained is of little importance. In that case, it is suggested
michael@0 60 * to consider non-repeatable entities as streamed, and those that are
michael@0 61 * repeatable (without a huge effort) as self-contained.
michael@0 62 *
michael@0 63 * @since 4.0
michael@0 64 */
michael@0 65 public interface HttpEntity {
michael@0 66
michael@0 67 /**
michael@0 68 * Tells if the entity is capable of producing its data more than once.
michael@0 69 * A repeatable entity's getContent() and writeTo(OutputStream) methods
michael@0 70 * can be called more than once whereas a non-repeatable entity's can not.
michael@0 71 * @return true if the entity is repeatable, false otherwise.
michael@0 72 */
michael@0 73 boolean isRepeatable();
michael@0 74
michael@0 75 /**
michael@0 76 * Tells about chunked encoding for this entity.
michael@0 77 * The primary purpose of this method is to indicate whether
michael@0 78 * chunked encoding should be used when the entity is sent.
michael@0 79 * For entities that are received, it can also indicate whether
michael@0 80 * the entity was received with chunked encoding.
michael@0 81 * <br/>
michael@0 82 * The behavior of wrapping entities is implementation dependent,
michael@0 83 * but should respect the primary purpose.
michael@0 84 *
michael@0 85 * @return <code>true</code> if chunked encoding is preferred for this
michael@0 86 * entity, or <code>false</code> if it is not
michael@0 87 */
michael@0 88 boolean isChunked();
michael@0 89
michael@0 90 /**
michael@0 91 * Tells the length of the content, if known.
michael@0 92 *
michael@0 93 * @return the number of bytes of the content, or
michael@0 94 * a negative number if unknown. If the content length is known
michael@0 95 * but exceeds {@link java.lang.Long#MAX_VALUE Long.MAX_VALUE},
michael@0 96 * a negative number is returned.
michael@0 97 */
michael@0 98 long getContentLength();
michael@0 99
michael@0 100 /**
michael@0 101 * Obtains the Content-Type header, if known.
michael@0 102 * This is the header that should be used when sending the entity,
michael@0 103 * or the one that was received with the entity. It can include a
michael@0 104 * charset attribute.
michael@0 105 *
michael@0 106 * @return the Content-Type header for this entity, or
michael@0 107 * <code>null</code> if the content type is unknown
michael@0 108 */
michael@0 109 Header getContentType();
michael@0 110
michael@0 111 /**
michael@0 112 * Obtains the Content-Encoding header, if known.
michael@0 113 * This is the header that should be used when sending the entity,
michael@0 114 * or the one that was received with the entity.
michael@0 115 * Wrapping entities that modify the content encoding should
michael@0 116 * adjust this header accordingly.
michael@0 117 *
michael@0 118 * @return the Content-Encoding header for this entity, or
michael@0 119 * <code>null</code> if the content encoding is unknown
michael@0 120 */
michael@0 121 Header getContentEncoding();
michael@0 122
michael@0 123 /**
michael@0 124 * Returns a content stream of the entity.
michael@0 125 * {@link #isRepeatable Repeatable} entities are expected
michael@0 126 * to create a new instance of {@link InputStream} for each invocation
michael@0 127 * of this method and therefore can be consumed multiple times.
michael@0 128 * Entities that are not {@link #isRepeatable repeatable} are expected
michael@0 129 * to return the same {@link InputStream} instance and therefore
michael@0 130 * may not be consumed more than once.
michael@0 131 * <p>
michael@0 132 * IMPORTANT: Please note all entity implementations must ensure that
michael@0 133 * all allocated resources are properly deallocated after
michael@0 134 * the {@link InputStream#close()} method is invoked.
michael@0 135 *
michael@0 136 * @return content stream of the entity.
michael@0 137 *
michael@0 138 * @throws IOException if the stream could not be created
michael@0 139 * @throws IllegalStateException
michael@0 140 * if content stream cannot be created.
michael@0 141 *
michael@0 142 * @see #isRepeatable()
michael@0 143 */
michael@0 144 InputStream getContent() throws IOException, IllegalStateException;
michael@0 145
michael@0 146 /**
michael@0 147 * Writes the entity content out to the output stream.
michael@0 148 * <p>
michael@0 149 * <p>
michael@0 150 * IMPORTANT: Please note all entity implementations must ensure that
michael@0 151 * all allocated resources are properly deallocated when this method
michael@0 152 * returns.
michael@0 153 *
michael@0 154 * @param outstream the output stream to write entity content to
michael@0 155 *
michael@0 156 * @throws IOException if an I/O error occurs
michael@0 157 */
michael@0 158 void writeTo(OutputStream outstream) throws IOException;
michael@0 159
michael@0 160 /**
michael@0 161 * Tells whether this entity depends on an underlying stream.
michael@0 162 * Streamed entities that read data directly from the socket should
michael@0 163 * return <code>true</code>. Self-contained entities should return
michael@0 164 * <code>false</code>. Wrapping entities should delegate this call
michael@0 165 * to the wrapped entity.
michael@0 166 *
michael@0 167 * @return <code>true</code> if the entity content is streamed,
michael@0 168 * <code>false</code> otherwise
michael@0 169 */
michael@0 170 boolean isStreaming(); // don't expect an exception here
michael@0 171
michael@0 172 /**
michael@0 173 * This method is deprecated since version 4.1. Please use standard
michael@0 174 * java convention to ensure resource deallocation by calling
michael@0 175 * {@link InputStream#close()} on the input stream returned by
michael@0 176 * {@link #getContent()}
michael@0 177 * <p>
michael@0 178 * This method is called to indicate that the content of this entity
michael@0 179 * is no longer required. All entity implementations are expected to
michael@0 180 * release all allocated resources as a result of this method
michael@0 181 * invocation. Content streaming entities are also expected to
michael@0 182 * dispose of the remaining content, if any. Wrapping entities should
michael@0 183 * delegate this call to the wrapped entity.
michael@0 184 * <p>
michael@0 185 * This method is of particular importance for entities being
michael@0 186 * received from a {@link HttpConnection connection}. The entity
michael@0 187 * needs to be consumed completely in order to re-use the connection
michael@0 188 * with keep-alive.
michael@0 189 *
michael@0 190 * @throws IOException if an I/O error occurs.
michael@0 191 *
michael@0 192 * @deprecated Use {@link ch.boye.httpclientandroidlib.util.EntityUtils#consume(HttpEntity)}
michael@0 193 *
michael@0 194 * @see #getContent() and #writeTo(OutputStream)
michael@0 195 */
michael@0 196 void consumeContent() throws IOException;
michael@0 197
michael@0 198 }

mercurial