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;
020
021import org.apache.hadoop.hbase.io.hfile.BlockType;
022import org.apache.hadoop.hbase.io.hfile.HFileContext;
023import org.apache.hadoop.hbase.util.Bytes;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * An encoding context that is created by a writer's encoder, and is shared
028 * across the writer's whole lifetime.
029 *
030 * @see HFileBlockDecodingContext for decoding
031 *
032 */
033@InterfaceAudience.Private
034public interface HFileBlockEncodingContext {
035
036  /**
037   * @return the block type after encoding
038   */
039  BlockType getBlockType();
040
041  /**
042   * @return the {@link DataBlockEncoding} encoding used
043   */
044  DataBlockEncoding getDataBlockEncoding();
045
046  /**
047   * Do any action that needs to be performed after the encoding.
048   * Compression is also included if a non-null compression algorithm is used
049   *
050   * @param blockType
051   * @throws IOException
052   */
053  void postEncoding(BlockType blockType) throws IOException;
054
055  /**
056   * Releases the resources used.
057   */
058  void close();
059
060  /**
061   * @return HFile context information
062   */
063  HFileContext getHFileContext();
064
065  /**
066   * Sets the encoding state.
067   * @param state
068   */
069  void setEncodingState(EncodingState state);
070
071  /**
072   * @return the encoding state
073   */
074  EncodingState getEncodingState();
075
076  /**
077   * @param data encoded bytes with header
078   * @param offset the offset in encoded data to start at
079   * @param length the number of encoded bytes
080   * @return Bytes with header which are ready to write out to disk.
081   *         This is compressed and encrypted bytes applying the set compression
082   *         algorithm and encryption. The bytes may be changed.
083   *         If need a Bytes reference for later use, clone the bytes and use that.
084   *         Null if the data doesn't need to be compressed and encrypted.
085   */
086  Bytes compressAndEncrypt(byte[] data, int offset, int length) throws IOException;
087}