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.*;
016
017/**
018 * Used for enabling decompression on requests and compression on responses, such as support for GZIP compression.
019 *
020 * <h5 class='topic'>Description</h5>
021 *
022 * Used to wrap input and output streams within compression/decompression streams.
023 *
024 * <p>
025 * Encoders are registered with <c>RestServlets</c> through the <ja>@Rest(encoders)</ja> annotation.
026 *
027 * <h5 class='section'>Notes:</h5><ul>
028 *    <li class='note'>This class is thread safe and reusable.
029 * </ul>
030 *
031 * <h5 class='section'>See Also:</h5><ul>
032 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.Encoders">Encoders</a>
033
034 * </ul>
035 */
036public abstract class Encoder {
037
038   /**
039    * Converts the specified compressed input stream into an uncompressed stream.
040    *
041    * @param is The compressed stream.
042    * @return The uncompressed stream.
043    * @throws IOException If any errors occur, such as on a stream that's not a valid GZIP input stream.
044    */
045   public abstract InputStream getInputStream(InputStream is) throws IOException;
046
047   /**
048    * Converts the specified uncompressed output stream into an uncompressed stream.
049    *
050    * @param os The uncompressed stream.
051    * @return The compressed stream stream.
052    * @throws IOException If any errors occur.
053    */
054   public abstract OutputStream getOutputStream(OutputStream os) throws IOException;
055
056   /**
057    * Returns the codings in <c>Content-Encoding</c> and <c>Accept-Encoding</c> headers that this encoder
058    * handles (e.g. <js>"gzip"</js>).
059    *
060    * @return The codings that this encoder handles.
061    */
062   public abstract String[] getCodings();
063}