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.classification.InterfaceAudience; 23 import org.apache.hadoop.hbase.io.compress.Compression; 24 import org.apache.hadoop.hbase.io.hfile.BlockType; 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 OutputStream to which encoded data is written 38 */ 39 OutputStream getOutputStreamForEncoder(); 40 41 /** 42 * @return encoded and compressed bytes with header which are ready to write 43 * out to disk 44 */ 45 byte[] getOnDiskBytesWithHeader(); 46 47 /** 48 * @return encoded but not heavily compressed bytes with header which can be 49 * cached in block cache 50 */ 51 byte[] getUncompressedBytesWithHeader(); 52 53 /** 54 * @return the block type after encoding 55 */ 56 BlockType getBlockType(); 57 58 /** 59 * @return the compression algorithm used by this encoding context 60 */ 61 Compression.Algorithm getCompression(); 62 63 /** 64 * sets the dummy header bytes 65 */ 66 void setDummyHeader(byte[] headerBytes); 67 68 /** 69 * @return the {@link DataBlockEncoding} encoding used 70 */ 71 DataBlockEncoding getDataBlockEncoding(); 72 73 /** 74 * Do any action that needs to be performed after the encoding. 75 * Compression is also included if {@link #getCompression()} returns non-null 76 * compression algorithm 77 * 78 * @param blockType 79 * @throws IOException 80 */ 81 void postEncoding(BlockType blockType) throws IOException; 82 83 /** 84 * Releases the resources used. 85 */ 86 void close(); 87 88 }