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