View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with this
4    * work for additional information regarding copyright ownership. The ASF
5    * licenses this file to you under the Apache License, Version 2.0 (the
6    * "License"); you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14   * License for the specific language governing permissions and limitations
15   * under the License.
16   */
17  package org.apache.hadoop.hbase.io.encoding;
18  
19  import java.io.IOException;
20  
21  import org.apache.hadoop.hbase.KeyValue.KVComparator;
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.io.hfile.BlockType;
24  import org.apache.hadoop.hbase.io.hfile.HFileContext;
25  
26  @InterfaceAudience.Private
27  public abstract class AbstractDataBlockEncoder implements DataBlockEncoder {
28  
29    @Override
30    public HFileBlockEncodingContext newDataBlockEncodingContext(
31        DataBlockEncoding encoding, byte[] header, HFileContext meta) {
32      return new HFileBlockDefaultEncodingContext(encoding, header, meta);
33    }
34  
35    @Override
36    public HFileBlockDecodingContext newDataBlockDecodingContext(HFileContext meta) {
37      return new HFileBlockDefaultDecodingContext(meta);
38    }
39  
40    protected void postEncoding(HFileBlockEncodingContext encodingCtx)
41        throws IOException {
42      if (encodingCtx.getDataBlockEncoding() != DataBlockEncoding.NONE) {
43        encodingCtx.postEncoding(BlockType.ENCODED_DATA);
44      } else {
45        encodingCtx.postEncoding(BlockType.DATA);
46      }
47    }
48  
49    protected abstract static class AbstractEncodedSeeker implements
50        EncodedSeeker {
51      protected HFileBlockDecodingContext decodingCtx;
52      protected final KVComparator comparator;
53  
54      public AbstractEncodedSeeker(KVComparator comparator,
55          HFileBlockDecodingContext decodingCtx) {
56        this.comparator = comparator;
57        this.decodingCtx = decodingCtx;
58      }
59  
60      protected boolean includesMvcc() {
61        return this.decodingCtx.getHFileContext().isIncludesMvcc();
62      }
63  
64      protected boolean includesTags() {
65        return this.decodingCtx.getHFileContext().isIncludesTags();
66      }
67    }
68  
69  }