001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.io.compress; 019 020import java.io.IOException; 021import java.nio.ByteBuffer; 022 023import org.apache.hadoop.classification.InterfaceAudience; 024import org.apache.hadoop.classification.InterfaceStability; 025 026/** 027 * Specification of a direct ByteBuffer 'de-compressor'. 028 */ 029@InterfaceAudience.Public 030@InterfaceStability.Evolving 031public interface DirectDecompressor { 032 /* 033 * This exposes a direct interface for record decompression with direct byte 034 * buffers. 035 * 036 * The decompress() function need not always consume the buffers provided, 037 * it will need to be called multiple times to decompress an entire buffer 038 * and the object will hold the compression context internally. 039 * 040 * Codecs such as {@link SnappyCodec} may or may not support partial 041 * decompression of buffers and will need enough space in the destination 042 * buffer to decompress an entire block. 043 * 044 * The operation is modelled around dst.put(src); 045 * 046 * The end result will move src.position() by the bytes-read and 047 * dst.position() by the bytes-written. It should not modify the src.limit() 048 * or dst.limit() to maintain consistency of operation between codecs. 049 * 050 * @param src Source direct {@link ByteBuffer} for reading from. Requires src 051 * != null and src.remaining() > 0 052 * 053 * @param dst Destination direct {@link ByteBuffer} for storing the results 054 * into. Requires dst != null and dst.remaining() to be > 0 055 * 056 * @throws IOException if compression fails 057 */ 058 public void decompress(ByteBuffer src, ByteBuffer dst) throws IOException; 059}