Java Code Examples for org.apache.hadoop.hbase.util.Bytes.readByteArray()

The following are Jave code examples for showing how to use readByteArray() of the org.apache.hadoop.hbase.util.Bytes class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ditb   File: IndexFile.java   View Source Code Vote up 6 votes
static BlockIndex readIndex(final RawComparator<byte []> c,
    DataInputStream in, final int indexSize)
throws IOException {
  BlockIndex bi = new BlockIndex(c);
  bi.blockOffsets = new long[indexSize];
  bi.blockKeys = new byte[indexSize][];
  bi.blockDataSizes = new int[indexSize];
  // If index size is zero, no index was written.
  if (indexSize > 0) {
    byte [] magic = new byte[INDEXBLOCKMAGIC.length];
    in.readFully(magic);
    if (!Arrays.equals(magic, INDEXBLOCKMAGIC)) {
      throw new IOException("Index block magic is wrong: " +
        Arrays.toString(magic));
    }
    for (int i = 0; i < indexSize; ++i ) {
      long offset   = in.readLong();
      int dataSize  = in.readInt();
      byte [] key = Bytes.readByteArray(in);
      bi.add(key, offset, dataSize);
    }
  }
  return bi;
}
 
Example 2
Project: ditb   File: IndexFile.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
public void readFields(DataInput in) throws IOException {
  // First clear the map. Otherwise we will just accumulate
  // entries every time this method is called.
  this.instance.clear();
  // Read the number of entries in the map
  int entries = in.readInt();
  // Then read each key/value pair
  for (int i = 0; i < entries; i++) {
    byte[] key = Bytes.readByteArray(in);
    byte id = in.readByte();
    Class clazz = getClass(id);
    V value = null;
    if (clazz.equals(byte[].class)) {
      byte[] bytes = Bytes.readByteArray(in);
      value = (V) bytes;
    } else {
      Writable w = (Writable) ReflectionUtils.newInstance(clazz, getConf());
      w.readFields(in);
      value = (V) w;
    }
    this.instance.put(key, value);
  }
}
 
Example 3
Project: ditb   File: HFileBlockIndex.java   View Source Code Vote up 6 votes
/**
 * Read in the root-level index from the given input stream. Must match
 * what was written into the root level by
 * {@link BlockIndexWriter#writeIndexBlocks(FSDataOutputStream)} at the
 * offset that function returned.
 *
 * @param in the buffered input stream or wrapped byte input stream
 * @param numEntries the number of root-level index entries
 * @throws IOException
 */
public void readRootIndex(DataInput in, final int numEntries)
    throws IOException {
  blockOffsets = new long[numEntries];
  blockKeys = new byte[numEntries][];
  blockDataSizes = new int[numEntries];

  // If index size is zero, no index was written.
  if (numEntries > 0) {
    for (int i = 0; i < numEntries; ++i) {
      long offset = in.readLong();
      int dataSize = in.readInt();
      byte[] key = Bytes.readByteArray(in);
      add(key, offset, dataSize);
    }
  }
}
 
Example 4
Project: ditb   File: Range.java   View Source Code Vote up 6 votes
@Override
public void readFields(DataInput in) throws IOException {
  column = Bytes.readByteArray(in);
  dataType = WritableUtils.readEnum(in, DataType.class);
  if (in.readBoolean()) {
    startType = WritableUtils.readEnum(in, CompareOp.class);
    startValue = Bytes.readByteArray(in);
  } else {
    startType = CompareOp.NO_OP;
    startValue = null;
  }
  if (in.readBoolean()) {
    stopType = WritableUtils.readEnum(in, CompareOp.class);
    stopValue = Bytes.readByteArray(in);
  } else {
    stopType = CompareOp.NO_OP;
    stopValue = null;
  }
}
 
Example 5
Project: ditb   File: TimeRangeFilter.java   View Source Code Vote up 6 votes
public void readFields(final DataInput in) throws IOException {
  this.columnFamily = Bytes.readByteArray(in);
  if (this.columnFamily.length == 0) {
    this.columnFamily = null;
  }
  this.columnQualifier = Bytes.readByteArray(in);
  if (this.columnQualifier.length == 0) {
    this.columnQualifier = null;
  }
  this.startTs = in.readLong();
  this.endTs = in.readLong();

  this.foundColumn = in.readBoolean();
  this.filterIfMissing = in.readBoolean();
  this.latestVersionOnly = in.readBoolean();
}
 
Example 6
Project: ditb   File: ScanRange.java   View Source Code Vote up 6 votes
@Override public void readFields(DataInput in) throws IOException {
  family = Bytes.readByteArray(in);
  qualifier = Bytes.readByteArray(in);
  boolean startNull = Bytes.toBoolean(Bytes.readByteArray(in));
  if (startNull) {
    start = null;
    startOp = CompareFilter.CompareOp.NO_OP;
  } else {
    start = Bytes.readByteArray(in);
    startOp = CompareFilter.CompareOp.valueOf(Bytes.toString(Bytes.readByteArray(in)));
  }
  boolean stopNull = Bytes.toBoolean(Bytes.readByteArray(in));
  if (stopNull) {
    stop = null;
    stopOp = CompareFilter.CompareOp.NO_OP;
  } else {
    stop = Bytes.readByteArray(in);
    stopOp = CompareFilter.CompareOp.valueOf(Bytes.toString(Bytes.readByteArray(in)));
  }
  startTs = in.readLong();
  stopTs = in.readLong();
  dataType = DataType.valueOf(Bytes.toString(Bytes.readByteArray(in)));
}
 
Example 7
Project: ditb   File: TableSplit.java   View Source Code Vote up 5 votes
/**
 * Reads the values of each field.
 *
 * @param in  The input to read from.
 * @throws IOException When reading the input fails.
 */
@Override
public void readFields(DataInput in) throws IOException {
  Version version = Version.UNVERSIONED;
  // TableSplit was not versioned in the beginning.
  // In order to introduce it now, we make use of the fact
  // that tableName was written with Bytes.writeByteArray,
  // which encodes the array length as a vint which is >= 0.
  // Hence if the vint is >= 0 we have an old version and the vint
  // encodes the length of tableName.
  // If < 0 we just read the version and the next vint is the length.
  // @see Bytes#readByteArray(DataInput)
  int len = WritableUtils.readVInt(in);
  if (len < 0) {
    // what we just read was the version
    version = Version.fromCode(len);
    len = WritableUtils.readVInt(in);
  }
  byte[] tableNameBytes = new byte[len];
  in.readFully(tableNameBytes);
  tableName = TableName.valueOf(tableNameBytes);
  startRow = Bytes.readByteArray(in);
  endRow = Bytes.readByteArray(in);
  regionLocation = Bytes.toString(Bytes.readByteArray(in));
  if (version.atLeast(Version.INITIAL)) {
    scan = Bytes.toString(Bytes.readByteArray(in));
  }
  length = WritableUtils.readVLong(in);
}
 
Example 8
Project: ditb   File: WALEdit.java   View Source Code Vote up 5 votes
@Override
public void readFields(DataInput in) throws IOException {
  cells.clear();
  if (scopes != null) {
    scopes.clear();
  }
  int versionOrLength = in.readInt();
  // TODO: Change version when we protobuf.  Also, change way we serialize KV!  Pb it too.
  if (versionOrLength == VERSION_2) {
    // this is new style WAL entry containing multiple KeyValues.
    int numEdits = in.readInt();
    for (int idx = 0; idx < numEdits; idx++) {
      if (compressionContext != null) {
        this.add(KeyValueCompression.readKV(in, compressionContext));
      } else {
        this.add(KeyValue.create(in));
      }
    }
    int numFamilies = in.readInt();
    if (numFamilies > 0) {
      if (scopes == null) {
        scopes = new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR);
      }
      for (int i = 0; i < numFamilies; i++) {
        byte[] fam = Bytes.readByteArray(in);
        int scope = in.readInt();
        scopes.put(fam, scope);
      }
    }
  } else {
    // this is an old style WAL entry. The int that we just
    // read is actually the length of a single KeyValue
    this.add(KeyValue.create(versionOrLength, in));
  }
}
 
Example 9
Project: ditb   File: Reference.java   View Source Code Vote up 5 votes
/**
 * @deprecated Writables are going away. Use the pb serialization methods instead.
 * Remove in a release after 0.96 goes out.  This is here only to migrate
 * old Reference files written with Writables before 0.96.
 */
@Deprecated
public void readFields(DataInput in) throws IOException {
  boolean tmp = in.readBoolean();
  // If true, set region to top.
  this.region = tmp? Range.top: Range.bottom;
  this.splitkey = Bytes.readByteArray(in);
}
 
Example 10
Project: ditb   File: HFile.java   View Source Code Vote up 5 votes
/** Now parse the old Writable format.  It was a list of Map entries.  Each map entry was a key and a value of
 * a byte [].  The old map format had a byte before each entry that held a code which was short for the key or
 * value type.  We know it was a byte [] so in below we just read and dump it.
 * @throws IOException
 */
void parseWritable(final DataInputStream in) throws IOException {
  // First clear the map.  Otherwise we will just accumulate entries every time this method is called.
  this.map.clear();
  // Read the number of entries in the map
  int entries = in.readInt();
  // Then read each key/value pair
  for (int i = 0; i < entries; i++) {
    byte[] key = Bytes.readByteArray(in);
    // We used to read a byte that encoded the class type.  Read and ignore it because it is always byte [] in hfile
    in.readByte();
    byte[] value = Bytes.readByteArray(in);
    this.map.put(key, value);
  }
}
 
Example 11
Project: ditb   File: TablePermission.java   View Source Code Vote up 5 votes
@Override
public void readFields(DataInput in) throws IOException {
  super.readFields(in);
  byte[] tableBytes = Bytes.readByteArray(in);
  table = TableName.valueOf(tableBytes);
  if (in.readBoolean()) {
    family = Bytes.readByteArray(in);
  }
  if (in.readBoolean()) {
    qualifier = Bytes.readByteArray(in);
  }
  if(in.readBoolean()) {
    namespace = Bytes.toString(Bytes.readByteArray(in));
  }
}
 
Example 12
Project: ditb   File: IndexDescriptor.java   View Source Code Vote up 5 votes
@Override
public void readFields(DataInput dataInput) throws IOException {
  super.readFields(dataInput);
  qualifier = Bytes.readByteArray(dataInput);
  type = WritableUtils.readEnum(dataInput, DataType.class);
  this.offset = dataInput.readInt();
  this.length = dataInput.readInt();
}
 
Example 13
Project: ditb   File: HRegionInfo.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use protobuf deserialization instead.
 * @see #parseFrom(byte[])
 */
@Deprecated
public void readFields(DataInput in) throws IOException {
  // Read the single version byte.  We don't ask the super class do it
  // because freaks out if its not the current classes' version.  This method
  // can deserialize version 0 and version 1 of HRI.
  byte version = in.readByte();
  if (version == 0) {
    // This is the old HRI that carried an HTD.  Migrate it.  The below
    // was copied from the old 0.90 HRI readFields.
    this.endKey = Bytes.readByteArray(in);
    this.offLine = in.readBoolean();
    this.regionId = in.readLong();
    this.regionName = Bytes.readByteArray(in);
    this.split = in.readBoolean();
    this.startKey = Bytes.readByteArray(in);
    try {
      HTableDescriptor htd = new HTableDescriptor();
      htd.readFields(in);
      this.tableName = htd.getTableName();
    } catch(EOFException eofe) {
       throw new IOException("HTD not found in input buffer", eofe);
    }
    this.hashCode = in.readInt();
  } else if (getVersion() == version) {
    this.endKey = Bytes.readByteArray(in);
    this.offLine = in.readBoolean();
    this.regionId = in.readLong();
    this.regionName = Bytes.readByteArray(in);
    this.split = in.readBoolean();
    this.startKey = Bytes.readByteArray(in);
    this.tableName = TableName.valueOf(Bytes.readByteArray(in));
    this.hashCode = in.readInt();
  } else {
    throw new IOException("Non-migratable/unknown version=" + getVersion());
  }
}
 
Example 14
Project: ditb   File: TableSplit.java   View Source Code Vote up 4 votes
public void readFields(DataInput in) throws IOException {
  this.m_tableName = TableName.valueOf(Bytes.readByteArray(in));
  this.m_startRow = Bytes.readByteArray(in);
  this.m_endRow = Bytes.readByteArray(in);
  this.m_regionLocation = Bytes.toString(Bytes.readByteArray(in));
}
 
Example 15
Project: ditb   File: HLogKey.java   View Source Code Vote up 4 votes
@Override
public void readFields(DataInput in) throws IOException {
  Version version = Version.UNVERSIONED;
  // HLogKey was not versioned in the beginning.
  // In order to introduce it now, we make use of the fact
  // that encodedRegionName was written with Bytes.writeByteArray,
  // which encodes the array length as a vint which is >= 0.
  // Hence if the vint is >= 0 we have an old version and the vint
  // encodes the length of encodedRegionName.
  // If < 0 we just read the version and the next vint is the length.
  // @see Bytes#readByteArray(DataInput)
  setScopes(null); // writable HLogKey does not contain scopes
  int len = WritableUtils.readVInt(in);
  byte[] tablenameBytes = null;
  if (len < 0) {
    // what we just read was the version
    version = Version.fromCode(len);
    // We only compress V2 of WALkey.
    // If compression is on, the length is handled by the dictionary
    if (compressionContext == null || !version.atLeast(Version.COMPRESSED)) {
      len = WritableUtils.readVInt(in);
    }
  }
  if (compressionContext == null || !version.atLeast(Version.COMPRESSED)) {
    this.encodedRegionName = new byte[len];
    in.readFully(this.encodedRegionName);
    tablenameBytes = Bytes.readByteArray(in);
  } else {
    this.encodedRegionName = Compressor.readCompressed(in, compressionContext.regionDict);
    tablenameBytes = Compressor.readCompressed(in, compressionContext.tableDict);
  }

  this.logSeqNum = in.readLong();
  this.writeTime = in.readLong();

  this.clusterIds.clear();
  if (version.atLeast(Version.INITIAL)) {
    if (in.readBoolean()) {
      // read the older log
      // Definitely is the originating cluster
      clusterIds.add(new UUID(in.readLong(), in.readLong()));
    }
  } else {
    try {
      // dummy read (former byte cluster id)
      in.readByte();
    } catch(EOFException e) {
      // Means it's a very old key, just continue
      if (LOG.isTraceEnabled()) LOG.trace(e);
    }
  }
  try {
    this.tablename = TableName.valueOf(tablenameBytes);
  } catch (IllegalArgumentException iae) {
    if (Bytes.toString(tablenameBytes).equals(TableName.OLD_META_STR)) {
      // It is a pre-namespace meta table edit, continue with new format.
      LOG.info("Got an old .META. edit, continuing with new format ");
      this.tablename = TableName.META_TABLE_NAME;
      this.encodedRegionName = HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes();
    } else if (Bytes.toString(tablenameBytes).equals(TableName.OLD_ROOT_STR)) {
      this.tablename = TableName.OLD_ROOT_TABLE_NAME;
       throw iae;
    } else throw iae;
  }
  // Do not need to read the clusters information as we are using protobufs from 0.95
}
 
Example 16
Project: ditb   File: UserPermission.java   View Source Code Vote up 4 votes
@Override
public void readFields(DataInput in) throws IOException {
  super.readFields(in);
  user = Bytes.readByteArray(in);
}