001/*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.io.encoding;
020
021import java.io.DataOutputStream;
022import java.io.IOException;
023
024import org.apache.hadoop.hbase.Cell;
025import org.apache.hadoop.hbase.KeyValue;
026import org.apache.hadoop.hbase.KeyValueUtil;
027import org.apache.hadoop.hbase.PrivateCellUtil;
028import org.apache.hadoop.io.WritableUtils;
029import org.apache.yetus.audience.InterfaceAudience;
030
031@InterfaceAudience.Private
032public class NoneEncoder {
033
034  private DataOutputStream out;
035  private HFileBlockDefaultEncodingContext encodingCtx;
036
037  public NoneEncoder(DataOutputStream out,
038      HFileBlockDefaultEncodingContext encodingCtx) {
039    this.out = out;
040    this.encodingCtx = encodingCtx;
041  }
042
043  public int write(Cell cell) throws IOException {
044    // We write tags seperately because though there is no tag in KV
045    // if the hfilecontext says include tags we need the tags length to be
046    // written
047    int size = KeyValueUtil.oswrite(cell, out, false);
048    // Write the additional tag into the stream
049    if (encodingCtx.getHFileContext().isIncludesTags()) {
050      int tagsLength = cell.getTagsLength();
051      out.writeShort(tagsLength);
052      if (tagsLength > 0) {
053        PrivateCellUtil.writeTags(out, cell, tagsLength);
054      }
055      size += tagsLength + KeyValue.TAGS_LENGTH_SIZE;
056    }
057    if (encodingCtx.getHFileContext().isIncludesMvcc()) {
058      WritableUtils.writeVLong(out, cell.getSequenceId());
059      size += WritableUtils.getVIntSize(cell.getSequenceId());
060    }
061    return size;
062  }
063
064}