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.compress; 019 020import java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.hbase.util.ClassSize; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * Holds HFile-level settings used by GzipByteBuffDecompressor. It's expensive to pull these from a 027 * Configuration object every time we decompress a block, so pull them upon opening an HFile, and 028 * reuse them in every block that gets decompressed. 029 */ 030@InterfaceAudience.Private 031public final class GzipHFileDecompressionContext extends Compression.HFileDecompressionContext { 032 033 public static final long FIXED_OVERHEAD = 034 ClassSize.estimateBase(GzipHFileDecompressionContext.class, false); 035 036 public static final String ALLOW_BYTE_BUFF_DECOMPRESSION_KEY = 037 "hbase.io.compress.gz.allowByteBuffDecompression"; 038 039 private final boolean allowByteBuffDecompression; 040 041 private GzipHFileDecompressionContext(boolean allowByteBuffDecompression) { 042 this.allowByteBuffDecompression = allowByteBuffDecompression; 043 } 044 045 public boolean isAllowByteBuffDecompression() { 046 return allowByteBuffDecompression; 047 } 048 049 public static GzipHFileDecompressionContext fromConfiguration(Configuration conf) { 050 return new GzipHFileDecompressionContext( 051 conf.getBoolean(ALLOW_BYTE_BUFF_DECOMPRESSION_KEY, true)); 052 } 053 054 @Override 055 public void close() throws IOException { 056 } 057 058 @Override 059 public long heapSize() { 060 return FIXED_OVERHEAD; 061 } 062 063 @Override 064 public String toString() { 065 return "GzipHFileDecompressionContext{allowByteBuffDecompression=" + allowByteBuffDecompression 066 + '}'; 067 } 068}