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.encoding;
019
020import java.io.DataOutputStream;
021import java.io.IOException;
022import org.apache.hadoop.hbase.Cell;
023import org.apache.hadoop.hbase.KeyValue;
024import org.apache.hadoop.hbase.KeyValueUtil;
025import org.apache.hadoop.hbase.PrivateCellUtil;
026import org.apache.hadoop.io.WritableUtils;
027import org.apache.yetus.audience.InterfaceAudience;
028
029@InterfaceAudience.Private
030public class NoneEncoder {
031
032  private DataOutputStream out;
033  private HFileBlockDefaultEncodingContext encodingCtx;
034
035  public NoneEncoder(DataOutputStream out, HFileBlockDefaultEncodingContext encodingCtx) {
036    this.out = out;
037    this.encodingCtx = encodingCtx;
038  }
039
040  public int write(Cell cell) throws IOException {
041    // We write tags seperately because though there is no tag in KV
042    // if the hfilecontext says include tags we need the tags length to be
043    // written
044    int size = KeyValueUtil.oswrite(cell, out, false);
045    // Write the additional tag into the stream
046    if (encodingCtx.getHFileContext().isIncludesTags()) {
047      int tagsLength = cell.getTagsLength();
048      out.writeShort(tagsLength);
049      if (tagsLength > 0) {
050        PrivateCellUtil.writeTags(out, cell, tagsLength);
051      }
052      size += tagsLength + KeyValue.TAGS_LENGTH_SIZE;
053    }
054    if (encodingCtx.getHFileContext().isIncludesMvcc()) {
055      WritableUtils.writeVLong(out, cell.getSequenceId());
056      size += WritableUtils.getVIntSize(cell.getSequenceId());
057    }
058    return size;
059  }
060
061}