001/*002 *003 * Licensed to the Apache Software Foundation (ASF) under one004 * or more contributor license agreements. See the NOTICE file005 * distributed with this work for additional information006 * regarding copyright ownership. The ASF licenses this file007 * to you under the Apache License, Version 2.0 (the008 * "License"); you may not use this file except in compliance009 * with the License. You may obtain a copy of the License at010 *011 * http://www.apache.org/licenses/LICENSE-2.0012 *013 * Unless required by applicable law or agreed to in writing, software014 * distributed under the License is distributed on an "AS IS" BASIS,015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.016 * See the License for the specific language governing permissions and017 * limitations under the License.018 */019package org.apache.hadoop.hbase.io.hfile;020021import java.io.DataOutput;022import java.io.IOException;023024import org.apache.yetus.audience.InterfaceAudience;025026/**027 * A way to write "inline" blocks into an {@link HFile}. Inline blocks are028 * interspersed with data blocks. For example, Bloom filter chunks and029 * leaf-level blocks of a multi-level block index are stored as inline blocks.030 */031@InterfaceAudience.Private032public interface InlineBlockWriter {033034 /**035 * Determines whether there is a new block to be written out.036 *037 * @param closing038 * whether the file is being closed, in which case we need to write039 * out all available data and not wait to accumulate another block040 */041 boolean shouldWriteBlock(boolean closing);042043 /**044 * Writes the block to the provided stream. Must not write any magic records.045 * Called only if {@link #shouldWriteBlock(boolean)} returned true.046 *047 * @param out048 * a stream (usually a compressing stream) to write the block to049 */050 void writeInlineBlock(DataOutput out) throws IOException;051052 /**053 * Called after a block has been written, and its offset, raw size, and054 * compressed size have been determined. Can be used to add an entry to a055 * block index. If this type of inline blocks needs a block index, the inline056 * block writer is responsible for maintaining it.057 *058 * @param offset the offset of the block in the stream059 * @param onDiskSize the on-disk size of the block060 * @param uncompressedSize the uncompressed size of the block061 */062 void blockWritten(long offset, int onDiskSize, int uncompressedSize);063064 /**065 * The type of blocks this block writer produces.066 */067 BlockType getInlineBlockType();068069 /**070 * @return true if inline blocks produced by this writer should be cached071 */072 boolean getCacheOnWrite();073}