001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.encoders;
014
015import java.io.*;
016import java.util.zip.*;
017
018/**
019 * Encoder for handling <js>"gzip"</js> encoding and decoding.
020 *
021 * <h5 class='section'>Notes:</h5><ul>
022 *    <li class='note'>This class is thread safe and reusable.
023 * </ul>
024 *
025 * <h5 class='section'>See Also:</h5><ul>
026 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.Encoders">Encoders</a>
027
028 * </ul>
029 */
030public class GzipEncoder extends Encoder {
031
032   @Override /* Encoder */
033   public OutputStream getOutputStream(OutputStream os) throws IOException {
034      return new FinishableGZIPOutputStream(os);
035   }
036
037   @Override /* Encoder */
038   public InputStream getInputStream(InputStream is) throws IOException {
039      return new GZIPInputStream(is);
040   }
041
042   /**
043    * Returns <code>[<js>"gzip"</js>]</code>.
044    */
045   @Override /* Encoder */
046   public String[] getCodings() {
047      return new String[]{"gzip"};
048   }
049
050   private static class FinishableGZIPOutputStream extends GZIPOutputStream implements Finishable {
051      FinishableGZIPOutputStream(OutputStream out) throws IOException {
052         super(out);
053      }
054   }
055}