View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with this
4    * work for additional information regarding copyright ownership. The ASF
5    * licenses this file to you under the Apache License, Version 2.0 (the
6    * "License"); you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14   * License for the specific language governing permissions and limitations
15   * under the License.
16   */
17  package org.apache.hadoop.hbase.io.encoding;
18  
19  import java.io.IOException;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.io.hfile.BlockType;
23  import org.apache.hadoop.hbase.io.hfile.HFileContext;
24  import org.apache.hadoop.hbase.util.Bytes;
25  
26  /**
27   * An encoding context that is created by a writer's encoder, and is shared
28   * across the writer's whole lifetime.
29   *
30   * @see HFileBlockDecodingContext for decoding
31   *
32   */
33  @InterfaceAudience.Private
34  public interface HFileBlockEncodingContext {
35  
36    /**
37     * @return the block type after encoding
38     */
39    BlockType getBlockType();
40  
41    /**
42     * @return the {@link DataBlockEncoding} encoding used
43     */
44    DataBlockEncoding getDataBlockEncoding();
45  
46    /**
47     * Do any action that needs to be performed after the encoding.
48     * Compression is also included if a non-null compression algorithm is used
49     *
50     * @param blockType
51     * @throws IOException
52     */
53    void postEncoding(BlockType blockType) throws IOException;
54  
55    /**
56     * Releases the resources used.
57     */
58    void close();
59  
60    /**
61     * @return HFile context information
62     */
63    HFileContext getHFileContext();
64  
65    /**
66     * Sets the encoding state.
67     * @param state
68     */
69    void setEncodingState(EncodingState state);
70  
71    /**
72     * @return the encoding state
73     */
74    EncodingState getEncodingState();
75  
76    /**
77     * @param data encoded bytes with header
78     * @param offset the offset in encoded data to start at
79     * @param length the number of encoded bytes
80     * @return Bytes with header which are ready to write out to disk.
81     *         This is compressed and encrypted bytes applying the set compression
82     *         algorithm and encryption. The bytes may be changed.
83     *         If need a Bytes reference for later use, clone the bytes and use that.
84     *         Null if the data doesn't need to be compressed and encrypted.
85     */
86    Bytes compressAndEncrypt(byte[] data, int offset, int length) throws IOException;
87  }