Home | History | Annotate | Download | only in entity
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/HttpEntityWrapper.java $
      3  * $Revision: 496070 $
      4  * $Date: 2007-01-14 04:18:34 -0800 (Sun, 14 Jan 2007) $
      5  *
      6  * ====================================================================
      7  * Licensed to the Apache Software Foundation (ASF) under one
      8  * or more contributor license agreements.  See the NOTICE file
      9  * distributed with this work for additional information
     10  * regarding copyright ownership.  The ASF licenses this file
     11  * to you under the Apache License, Version 2.0 (the
     12  * "License"); you may not use this file except in compliance
     13  * with the License.  You may obtain a copy of the License at
     14  *
     15  *   http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  * Unless required by applicable law or agreed to in writing,
     18  * software distributed under the License is distributed on an
     19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     20  * KIND, either express or implied.  See the License for the
     21  * specific language governing permissions and limitations
     22  * under the License.
     23  * ====================================================================
     24  *
     25  * This software consists of voluntary contributions made by many
     26  * individuals on behalf of the Apache Software Foundation.  For more
     27  * information on the Apache Software Foundation, please see
     28  * <http://www.apache.org/>.
     29  *
     30  */
     31 
     32 package org.apache.http.entity;
     33 
     34 import java.io.IOException;
     35 import java.io.InputStream;
     36 import java.io.OutputStream;
     37 
     38 import org.apache.http.Header;
     39 import org.apache.http.HttpEntity;
     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  * @version $Revision: 496070 $
     49  *
     50  * @since 4.0
     51  */
     52 public class HttpEntityWrapper implements HttpEntity {
     53 
     54     /** The wrapped entity. */
     55     protected HttpEntity wrappedEntity;
     56 
     57     /**
     58      * Creates a new entity wrapper.
     59      *
     60      * @param wrapped   the entity to wrap
     61      */
     62     public HttpEntityWrapper(HttpEntity wrapped) {
     63         super();
     64 
     65         if (wrapped == null) {
     66             throw new IllegalArgumentException
     67                 ("wrapped entity must not be null");
     68         }
     69         wrappedEntity = wrapped;
     70 
     71     } // constructor
     72 
     73 
     74     public boolean isRepeatable() {
     75         return wrappedEntity.isRepeatable();
     76     }
     77 
     78     public boolean isChunked() {
     79         return wrappedEntity.isChunked();
     80     }
     81 
     82     public long getContentLength() {
     83         return wrappedEntity.getContentLength();
     84     }
     85 
     86     public Header getContentType() {
     87         return wrappedEntity.getContentType();
     88     }
     89 
     90     public Header getContentEncoding() {
     91         return wrappedEntity.getContentEncoding();
     92     }
     93 
     94     public InputStream getContent()
     95         throws IOException {
     96         return wrappedEntity.getContent();
     97     }
     98 
     99     public void writeTo(OutputStream outstream)
    100         throws IOException {
    101         wrappedEntity.writeTo(outstream);
    102     }
    103 
    104     public boolean isStreaming() {
    105         return wrappedEntity.isStreaming();
    106     }
    107 
    108     public void consumeContent()
    109         throws IOException {
    110         wrappedEntity.consumeContent();
    111     }
    112 
    113 } // class HttpEntityWrapper
    114