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