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 <code>RestServlets</code> through the <ja>@RestResource.encoders()</ja> annotation. 026 */ 027public abstract class Encoder { 028 029 /** 030 * Converts the specified compressed input stream into an uncompressed stream. 031 * 032 * @param is The compressed stream. 033 * @return The uncompressed stream. 034 * @throws IOException If any errors occur, such as on a stream that's not a valid GZIP input stream. 035 */ 036 public abstract InputStream getInputStream(InputStream is) throws IOException; 037 038 /** 039 * Converts the specified uncompressed output stream into an uncompressed stream. 040 * 041 * @param os The uncompressed stream. 042 * @return The compressed stream stream. 043 * @throws IOException If any errors occur. 044 */ 045 public abstract OutputStream getOutputStream(OutputStream os) throws IOException; 046 047 /** 048 * Returns the codings in <code>Content-Encoding</code> and <code>Accept-Encoding</code> headers that this encoder 049 * handles (e.g. <js>"gzip"</js>). 050 * 051 * @return The codings that this encoder handles. 052 */ 053 public abstract String[] getCodings(); 054}