View Javadoc
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.hc.core5.http.io.entity;
29  
30  import java.io.IOException;
31  import java.io.InputStream;
32  import java.io.OutputStream;
33  import java.util.List;
34  import java.util.Set;
35  
36  import org.apache.hc.core5.http.Header;
37  import org.apache.hc.core5.http.HttpEntity;
38  import org.apache.hc.core5.function.Supplier;
39  import org.apache.hc.core5.util.Args;
40  
41  /**
42   * Base class for wrapping entities.
43   * Keeps a {@link #wrappedEntity wrappedEntity} and delegates all
44   * calls to it. Implementations of wrapping entities can derive
45   * from this class and need to override only those methods that
46   * should not be delegated to the wrapped entity.
47   *
48   * @since 4.0
49   */
50  public class HttpEntityWrapper implements HttpEntity {
51  
52      /** The wrapped entity. */
53      private final HttpEntity wrappedEntity;
54  
55      /**
56       * Creates a new entity wrapper.
57       */
58      public HttpEntityWrapper(final HttpEntity wrappedEntity) {
59          super();
60          this.wrappedEntity = Args.notNull(wrappedEntity, "Wrapped entity");
61      } // constructor
62  
63      @Override
64      public boolean isRepeatable() {
65          return wrappedEntity.isRepeatable();
66      }
67  
68      @Override
69      public boolean isChunked() {
70          return wrappedEntity.isChunked();
71      }
72  
73      @Override
74      public long getContentLength() {
75          return wrappedEntity.getContentLength();
76      }
77  
78      @Override
79      public String getContentType() {
80          return wrappedEntity.getContentType();
81      }
82  
83      @Override
84      public String getContentEncoding() {
85          return wrappedEntity.getContentEncoding();
86      }
87  
88      @Override
89      public InputStream getContent()
90          throws IOException {
91          return wrappedEntity.getContent();
92      }
93  
94      @Override
95      public void writeTo(final OutputStream outstream)
96          throws IOException {
97          wrappedEntity.writeTo(outstream);
98      }
99  
100     @Override
101     public boolean isStreaming() {
102         return wrappedEntity.isStreaming();
103     }
104 
105     @Override
106     public Supplier<List<? extends Header>> getTrailers() {
107         return wrappedEntity.getTrailers();
108     }
109 
110     @Override
111     public Set<String> getTrailerNames() {
112         return wrappedEntity.getTrailerNames();
113     }
114 
115     @Override
116     public void close() throws IOException {
117         wrappedEntity.close();
118     }
119 
120 }