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