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 */
27
28 package org.apache.http.entity;
29
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.OutputStream;
33
34 import org.apache.http.Header;
35 import org.apache.http.HttpEntity;
36 import org.apache.http.annotation.NotThreadSafe;
37 import org.apache.http.util.Args;
38
39 /**
40 * Base class for wrapping entities.
41 * Keeps a {@link #wrappedEntity wrappedEntity} and delegates all
42 * calls to it. Implementations of wrapping entities can derive
43 * from this class and need to override only those methods that
44 * should not be delegated to the wrapped entity.
45 *
46 * @since 4.0
47 */
48 @NotThreadSafe
49 public class HttpEntityWrapper implements HttpEntity {
50
51 /** The wrapped entity. */
52 protected HttpEntity wrappedEntity;
53
54 /**
55 * Creates a new entity wrapper.
56 */
57 public HttpEntityWrapper(final HttpEntity wrappedEntity) {
58 super();
59 this.wrappedEntity = Args.notNull(wrappedEntity, "Wrapped entity");
60 } // constructor
61
62 public boolean isRepeatable() {
63 return wrappedEntity.isRepeatable();
64 }
65
66 public boolean isChunked() {
67 return wrappedEntity.isChunked();
68 }
69
70 public long getContentLength() {
71 return wrappedEntity.getContentLength();
72 }
73
74 public Header getContentType() {
75 return wrappedEntity.getContentType();
76 }
77
78 public Header getContentEncoding() {
79 return wrappedEntity.getContentEncoding();
80 }
81
82 public InputStream getContent()
83 throws IOException {
84 return wrappedEntity.getContent();
85 }
86
87 public void writeTo(final OutputStream outstream)
88 throws IOException {
89 wrappedEntity.writeTo(outstream);
90 }
91
92 public boolean isStreaming() {
93 return wrappedEntity.isStreaming();
94 }
95
96 /**
97 * @deprecated (4.1) Either use {@link #getContent()} and call {@link java.io.InputStream#close()} on that;
98 * otherwise call {@link #writeTo(OutputStream)} which is required to free the resources.
99 */
100 @Deprecated
101 public void consumeContent() throws IOException {
102 wrappedEntity.consumeContent();
103 }
104
105 }