001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http.entity;
029
030import java.io.IOException;
031import java.io.InputStream;
032import java.io.OutputStream;
033
034import org.apache.http.Header;
035import org.apache.http.HttpEntity;
036import org.apache.http.util.Args;
037
038/**
039 * Base class for wrapping entities.
040 * Keeps a {@link #wrappedEntity wrappedEntity} and delegates all
041 * calls to it. Implementations of wrapping entities can derive
042 * from this class and need to override only those methods that
043 * should not be delegated to the wrapped entity.
044 *
045 * @since 4.0
046 */
047public class HttpEntityWrapper implements HttpEntity {
048
049    /** The wrapped entity. */
050    protected HttpEntity wrappedEntity;
051
052    /**
053     * Creates a new entity wrapper.
054     */
055    public HttpEntityWrapper(final HttpEntity wrappedEntity) {
056        super();
057        this.wrappedEntity = Args.notNull(wrappedEntity, "Wrapped entity");
058    } // constructor
059
060    @Override
061    public boolean isRepeatable() {
062        return wrappedEntity.isRepeatable();
063    }
064
065    @Override
066    public boolean isChunked() {
067        return wrappedEntity.isChunked();
068    }
069
070    @Override
071    public long getContentLength() {
072        return wrappedEntity.getContentLength();
073    }
074
075    @Override
076    public Header getContentType() {
077        return wrappedEntity.getContentType();
078    }
079
080    @Override
081    public Header getContentEncoding() {
082        return wrappedEntity.getContentEncoding();
083    }
084
085    @Override
086    public InputStream getContent()
087        throws IOException {
088        return wrappedEntity.getContent();
089    }
090
091    @Override
092    public void writeTo(final OutputStream outstream)
093        throws IOException {
094        wrappedEntity.writeTo(outstream);
095    }
096
097    @Override
098    public boolean isStreaming() {
099        return wrappedEntity.isStreaming();
100    }
101
102    /**
103     * @deprecated (4.1) Either use {@link #getContent()} and call {@link java.io.InputStream#close()} on that;
104     * otherwise call {@link #writeTo(OutputStream)} which is required to free the resources.
105     */
106    @Override
107    @Deprecated
108    public void consumeContent() throws IOException {
109        wrappedEntity.consumeContent();
110    }
111
112}