[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 | |
---|
| 23 | /** |
---|
| 24 | * Specification of a stream-based 'compressor' which can be |
---|
| 25 | * plugged into a {@link CompressionOutputStream} to compress data. |
---|
| 26 | * This is modelled after {@link java.util.zip.Deflater} |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | public interface Compressor { |
---|
| 30 | /** |
---|
| 31 | * Sets input data for compression. |
---|
| 32 | * This should be called whenever #needsInput() returns |
---|
| 33 | * <code>true</code> indicating that more input data is required. |
---|
| 34 | * |
---|
| 35 | * @param b Input data |
---|
| 36 | * @param off Start offset |
---|
| 37 | * @param len Length |
---|
| 38 | */ |
---|
| 39 | public void setInput(byte[] b, int off, int len); |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Returns true if the input data buffer is empty and |
---|
| 43 | * #setInput() should be called to provide more input. |
---|
| 44 | * |
---|
| 45 | * @return <code>true</code> if the input data buffer is empty and |
---|
| 46 | * #setInput() should be called in order to provide more input. |
---|
| 47 | */ |
---|
| 48 | public boolean needsInput(); |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * Sets preset dictionary for compression. A preset dictionary |
---|
| 52 | * is used when the history buffer can be predetermined. |
---|
| 53 | * |
---|
| 54 | * @param b Dictionary data bytes |
---|
| 55 | * @param off Start offset |
---|
| 56 | * @param len Length |
---|
| 57 | */ |
---|
| 58 | public void setDictionary(byte[] b, int off, int len); |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * Return number of uncompressed bytes input so far. |
---|
| 62 | */ |
---|
| 63 | public long getBytesRead(); |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * Return number of compressed bytes output so far. |
---|
| 67 | */ |
---|
| 68 | public long getBytesWritten(); |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * When called, indicates that compression should end |
---|
| 72 | * with the current contents of the input buffer. |
---|
| 73 | */ |
---|
| 74 | public void finish(); |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * Returns true if the end of the compressed |
---|
| 78 | * data output stream has been reached. |
---|
| 79 | * @return <code>true</code> if the end of the compressed |
---|
| 80 | * data output stream has been reached. |
---|
| 81 | */ |
---|
| 82 | public boolean finished(); |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * Fills specified buffer with compressed data. Returns actual number |
---|
| 86 | * of bytes of compressed data. A return value of 0 indicates that |
---|
| 87 | * needsInput() should be called in order to determine if more input |
---|
| 88 | * data is required. |
---|
| 89 | * |
---|
| 90 | * @param b Buffer for the compressed data |
---|
| 91 | * @param off Start offset of the data |
---|
| 92 | * @param len Size of the buffer |
---|
| 93 | * @return The actual number of bytes of compressed data. |
---|
| 94 | */ |
---|
| 95 | public int compress(byte[] b, int off, int len) throws IOException; |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | * Resets compressor so that a new set of input data can be processed. |
---|
| 99 | */ |
---|
| 100 | public void reset(); |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Closes the compressor and discards any unprocessed input. |
---|
| 104 | */ |
---|
| 105 | public void end(); |
---|
| 106 | } |
---|