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 */
027package org.apache.http.client.entity;
028
029import java.io.IOException;
030import java.io.InputStream;
031
032import org.apache.http.HttpEntity;
033
034/**
035 * {@link org.apache.http.entity.HttpEntityWrapper} responsible for handling
036 * deflate Content Coded responses. In RFC2616 terms, {@code deflate}
037 * means a {@code zlib} stream as defined in RFC1950. Some server
038 * implementations have misinterpreted RFC2616 to mean that a
039 * {@code deflate} stream as defined in RFC1951 should be used
040 * (or maybe they did that since that's how IE behaves?). It's confusing
041 * that {@code deflate} in HTTP 1.1 means {@code zlib} streams
042 * rather than {@code deflate} streams. We handle both types in here,
043 * since that's what is seen on the internet. Moral - prefer
044 * {@code gzip}!
045 *
046 * @see GzipDecompressingEntity
047 *
048 * @since 4.1
049 */
050public class DeflateDecompressingEntity extends DecompressingEntity {
051
052    /**
053     * Creates a new {@link DeflateDecompressingEntity} which will wrap the specified
054     * {@link HttpEntity}.
055     *
056     * @param entity
057     *            a non-null {@link HttpEntity} to be wrapped
058     */
059    public DeflateDecompressingEntity(final HttpEntity entity) {
060        super(entity, new InputStreamFactory() {
061
062            @Override
063            public InputStream create(final InputStream instream) throws IOException {
064                return new DeflateInputStream(instream);
065            }
066
067        });
068    }
069
070}