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  import java.io.OutputStream;
21  
22  import org.apache.hadoop.hbase.io.compress.Compression;
23  import org.apache.hadoop.hbase.io.hfile.BlockType;
24  
25  /**
26   * An encoding context that is created by a writer's encoder, and is shared
27   * across the writer's whole lifetime.
28   *
29   * @see HFileBlockDecodingContext for decoding
30   *
31   */
32  public interface HFileBlockEncodingContext {
33  
34    /**
35     * @return OutputStream to which encoded data is written
36     */
37    OutputStream getOutputStreamForEncoder();
38  
39    /**
40     * @return encoded and compressed bytes with header which are ready to write
41     *         out to disk
42     */
43    byte[] getOnDiskBytesWithHeader();
44  
45    /**
46     * @return encoded but not heavily compressed bytes with header which can be
47     *         cached in block cache
48     */
49    byte[] getUncompressedBytesWithHeader();
50  
51    /**
52     * @return the block type after encoding
53     */
54    BlockType getBlockType();
55  
56    /**
57     * @return the compression algorithm used by this encoding context
58     */
59    Compression.Algorithm getCompression();
60  
61    /**
62     * sets the dummy header bytes
63     */
64    void setDummyHeader(byte[] headerBytes);
65  
66    /**
67     * @return the {@link DataBlockEncoding} encoding used
68     */
69    DataBlockEncoding getDataBlockEncoding();
70  
71    /**
72     * Do any action that needs to be performed after the encoding.
73     * Compression is also included if {@link #getCompression()} returns non-null
74     * compression algorithm
75     *
76     * @param blockType
77     * @throws IOException
78     */
79    void postEncoding(BlockType blockType) throws IOException;
80  
81    /**
82     * Releases the resources used.
83     */
84    void close();
85  
86  }