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.hfile;
18  
19  import java.io.IOException;
20  import java.nio.ByteBuffer;
21  
22  import org.apache.hadoop.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
24  import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25  import org.apache.hadoop.hbase.io.encoding.HFileBlockDecodingContext;
26  import org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultDecodingContext;
27  import org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext;
28  import org.apache.hadoop.hbase.io.encoding.HFileBlockEncodingContext;
29  
30  /**
31   * Does not perform any kind of encoding/decoding.
32   */
33  @InterfaceAudience.Private
34  public class NoOpDataBlockEncoder implements HFileDataBlockEncoder {
35  
36    public static final NoOpDataBlockEncoder INSTANCE =
37        new NoOpDataBlockEncoder();
38  
39    /** Cannot be instantiated. Use {@link #INSTANCE} instead. */
40    private NoOpDataBlockEncoder() {
41    }
42  
43    @Override
44    public void beforeWriteToDisk(ByteBuffer in,
45        boolean includesMemstoreTS,
46        HFileBlockEncodingContext encodeCtx, BlockType blockType)
47        throws IOException {
48      if (!(encodeCtx.getClass().getName().equals(
49          HFileBlockDefaultEncodingContext.class.getName()))) {
50        throw new IOException (this.getClass().getName() + " only accepts " +
51            HFileBlockDefaultEncodingContext.class.getName() + ".");
52      }
53  
54      HFileBlockDefaultEncodingContext defaultContext =
55          (HFileBlockDefaultEncodingContext) encodeCtx;
56      defaultContext.compressAfterEncodingWithBlockType(in.array(), blockType);
57    }
58  
59    @Override
60    public boolean useEncodedScanner() {
61      return false;
62    }
63  
64    @Override
65    public void saveMetadata(HFile.Writer writer) {
66    }
67  
68    @Override
69    public DataBlockEncoding getDataBlockEncoding() {
70      return DataBlockEncoding.NONE;
71    }
72  
73    @Override
74    public String toString() {
75      return getClass().getSimpleName();
76    }
77  
78    @Override
79    public HFileBlockEncodingContext newDataBlockEncodingContext(
80        Algorithm compressionAlgorithm, byte[] dummyHeader) {
81      return new HFileBlockDefaultEncodingContext(compressionAlgorithm,
82          null, dummyHeader);
83    }
84  
85    @Override
86    public HFileBlockDecodingContext newDataBlockDecodingContext(
87        Algorithm compressionAlgorithm) {
88      return new HFileBlockDefaultDecodingContext(compressionAlgorithm);
89    }
90  
91  }