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  /**
035   * @return the block type after encoding
036   */
037  BlockType getBlockType();
038
039  /**
040   * @return the {@link DataBlockEncoding} encoding used
041   */
042  DataBlockEncoding getDataBlockEncoding();
043
044  /**
045   * Do any action that needs to be performed after the encoding. Compression is also included if a
046   * non-null compression algorithm is used
047   */
048  void postEncoding(BlockType blockType) throws IOException;
049
050  /**
051   * Releases the resources used.
052   */
053  void close();
054
055  /**
056   * @return HFile context information
057   */
058  HFileContext getHFileContext();
059
060  /**
061   * Sets the encoding state.
062   */
063  void setEncodingState(EncodingState state);
064
065  /**
066   * @return the encoding state
067   */
068  EncodingState getEncodingState();
069
070  /**
071   * @param data   encoded bytes with header
072   * @param offset the offset in encoded data to start at
073   * @param length the number of encoded bytes
074   * @return Bytes with header which are ready to write out to disk. This is compressed and
075   *         encrypted bytes applying the set compression algorithm and encryption. The bytes may be
076   *         changed. If need a Bytes reference for later use, clone the bytes and use that. Null if
077   *         the data doesn't need to be compressed and encrypted.
078   */
079  Bytes compressAndEncrypt(byte[] data, int offset, int length) throws IOException;
080}