[120] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
| 3 | * or more contributor license agreements. See the NOTICE file |
---|
| 4 | * distributed with this work for additional information |
---|
| 5 | * regarding copyright ownership. The ASF licenses this file |
---|
| 6 | * to you under the Apache License, Version 2.0 (the |
---|
| 7 | * "License"); you may not use this file except in compliance |
---|
| 8 | * with the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | package org.apache.hadoop.io.compress; |
---|
| 20 | |
---|
| 21 | import java.io.IOException; |
---|
| 22 | import java.io.InputStream; |
---|
| 23 | import java.io.OutputStream; |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | * This class encapsulates a streaming compression/decompression pair. |
---|
| 27 | */ |
---|
| 28 | public interface CompressionCodec { |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | * Create a {@link CompressionOutputStream} that will write to the given |
---|
| 32 | * {@link OutputStream}. |
---|
| 33 | * |
---|
| 34 | * @param out the location for the final output stream |
---|
| 35 | * @return a stream the user can write uncompressed data to have it compressed |
---|
| 36 | * @throws IOException |
---|
| 37 | */ |
---|
| 38 | CompressionOutputStream createOutputStream(OutputStream out) |
---|
| 39 | throws IOException; |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Create a {@link CompressionOutputStream} that will write to the given |
---|
| 43 | * {@link OutputStream} with the given {@link Compressor}. |
---|
| 44 | * |
---|
| 45 | * @param out the location for the final output stream |
---|
| 46 | * @param compressor compressor to use |
---|
| 47 | * @return a stream the user can write uncompressed data to have it compressed |
---|
| 48 | * @throws IOException |
---|
| 49 | */ |
---|
| 50 | CompressionOutputStream createOutputStream(OutputStream out, |
---|
| 51 | Compressor compressor) |
---|
| 52 | throws IOException; |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * Get the type of {@link Compressor} needed by this {@link CompressionCodec}. |
---|
| 56 | * |
---|
| 57 | * @return the type of compressor needed by this codec. |
---|
| 58 | */ |
---|
| 59 | Class<? extends Compressor> getCompressorType(); |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * Create a new {@link Compressor} for use by this {@link CompressionCodec}. |
---|
| 63 | * |
---|
| 64 | * @return a new compressor for use by this codec |
---|
| 65 | */ |
---|
| 66 | Compressor createCompressor(); |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * Create a stream decompressor that will read from the given input stream. |
---|
| 70 | * |
---|
| 71 | * @param in the stream to read compressed bytes from |
---|
| 72 | * @return a stream to read uncompressed bytes from |
---|
| 73 | * @throws IOException |
---|
| 74 | */ |
---|
| 75 | CompressionInputStream createInputStream(InputStream in) throws IOException; |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | * Create a {@link CompressionInputStream} that will read from the given |
---|
| 79 | * {@link InputStream} with the given {@link Decompressor}. |
---|
| 80 | * |
---|
| 81 | * @param in the stream to read compressed bytes from |
---|
| 82 | * @param decompressor decompressor to use |
---|
| 83 | * @return a stream to read uncompressed bytes from |
---|
| 84 | * @throws IOException |
---|
| 85 | */ |
---|
| 86 | CompressionInputStream createInputStream(InputStream in, |
---|
| 87 | Decompressor decompressor) |
---|
| 88 | throws IOException; |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * Get the type of {@link Decompressor} needed by this {@link CompressionCodec}. |
---|
| 93 | * |
---|
| 94 | * @return the type of decompressor needed by this codec. |
---|
| 95 | */ |
---|
| 96 | Class<? extends Decompressor> getDecompressorType(); |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * Create a new {@link Decompressor} for use by this {@link CompressionCodec}. |
---|
| 100 | * |
---|
| 101 | * @return a new decompressor for use by this codec |
---|
| 102 | */ |
---|
| 103 | Decompressor createDecompressor(); |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Get the default filename extension for this kind of compression. |
---|
| 107 | * @return the extension including the '.' |
---|
| 108 | */ |
---|
| 109 | String getDefaultExtension(); |
---|
| 110 | } |
---|