View Javadoc

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  package org.apache.hadoop.hbase.codec;
19  
20  import java.io.InputStream;
21  import java.io.OutputStream;
22  import java.nio.ByteBuffer;
23  
24  import org.apache.hadoop.hbase.CellScanner;
25  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26  import org.apache.hadoop.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.io.CellOutputStream;
28  
29  /**
30   * Encoder/Decoder for Cell.
31   *
32   * <p>Like {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoder} 
33   * only Cell-based rather than KeyValue version 1 based
34   * and without presuming an hfile context.  Intent is an Interface that will work for hfile and
35   * rpc.
36   */
37  @InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
38  public interface Codec {
39    // TODO: interfacing with {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoder}
40    /**
41     * Call flush when done.  Some encoders may not put anything on the stream until flush is called.
42     * On flush, let go of any resources used by the encoder.
43     */
44    interface Encoder extends CellOutputStream {}
45  
46    /**
47     * Implementations should implicitly clean up any resources allocated when the
48     * Decoder/CellScanner runs off the end of the cell block. Do this rather than require the user
49     * call close explicitly.
50     */
51    interface Decoder extends CellScanner {};
52  
53    Decoder getDecoder(InputStream is);
54    Decoder getDecoder(ByteBuffer buf);
55    Encoder getEncoder(OutputStream os);
56  }