001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with this
004 * work for additional information regarding copyright ownership. The ASF
005 * licenses this file to you under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017package org.apache.hadoop.hbase.io.encoding;
018
019import java.io.IOException;
020import org.apache.hadoop.hbase.io.hfile.BlockType;
021import org.apache.hadoop.hbase.io.hfile.HFileContext;
022import org.apache.hadoop.hbase.util.Bytes;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * An encoding context that is created by a writer's encoder, and is shared
027 * across the writer's whole lifetime.
028 *
029 * @see HFileBlockDecodingContext for decoding
030 *
031 */
032@InterfaceAudience.Private
033public interface HFileBlockEncodingContext {
034
035  /**
036   * @return the block type after encoding
037   */
038  BlockType getBlockType();
039
040  /**
041   * @return the {@link DataBlockEncoding} encoding used
042   */
043  DataBlockEncoding getDataBlockEncoding();
044
045  /**
046   * Do any action that needs to be performed after the encoding.
047   * Compression is also included if a non-null compression algorithm is used
048   */
049  void postEncoding(BlockType blockType) throws IOException;
050
051  /**
052   * Releases the resources used.
053   */
054  void close();
055
056  /**
057   * @return HFile context information
058   */
059  HFileContext getHFileContext();
060
061  /**
062   * Sets the encoding state.
063   */
064  void setEncodingState(EncodingState state);
065
066  /**
067   * @return the encoding state
068   */
069  EncodingState getEncodingState();
070
071  /**
072   * @param data encoded bytes with header
073   * @param offset the offset in encoded data to start at
074   * @param length the number of encoded bytes
075   * @return Bytes with header which are ready to write out to disk.
076   *         This is compressed and encrypted bytes applying the set compression
077   *         algorithm and encryption. The bytes may be changed.
078   *         If need a Bytes reference for later use, clone the bytes and use that.
079   *         Null if the data doesn't need to be compressed and encrypted.
080   */
081  Bytes compressAndEncrypt(byte[] data, int offset, int length) throws IOException;
082}