Java Code Examples for org.apache.hadoop.hbase.KeyValue#write()

The following examples show how to use org.apache.hadoop.hbase.KeyValue#write() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void validate(KeyValue kv, byte[] row, byte[] family, byte[] qualifier, long ts,
    Type type, byte[] value) throws IOException {
  DataOutputBuffer out = new DataOutputBuffer();
  kv.write(out);
  out.close();
  byte[] data = out.getData();
  // read it back in
  KeyValue read = new KeyValue();
  DataInputBuffer in = new DataInputBuffer();
  in.reset(data, data.length);
  read.readFields(in);
  in.close();

  // validate that its the same
  assertTrue("Row didn't match!", Bytes.equals(row, read.getRow()));
  assertTrue("Family didn't match!", Bytes.equals(family, read.getFamily()));
  assertTrue("Qualifier didn't match!", Bytes.equals(qualifier, read.getQualifier()));
  assertTrue("Value didn't match!", Bytes.equals(value, read.getValue()));
  assertEquals("Timestamp didn't match", ts, read.getTimestamp());
  assertEquals("Type didn't match", type.getCode(), read.getType());
}
 
Example 2
Source Project: phoenix   File: KeyValueCodec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
 * back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
 * @param out to write to
 * @param kv {@link KeyValue} to which to write
 * @throws IOException if there is an error writing
 */
public static void write(DataOutput out, KeyValue kv) throws IOException {
  if (kv instanceof IndexedKeyValue) {
    out.writeInt(INDEX_TYPE_LENGTH_MARKER);
    ((IndexedKeyValue) kv).writeData(out);
  } else {
      KeyValue.write(kv, out);
  }
}
 
Example 3
Source Project: phoenix   File: KeyValueCodec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
 * back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
 * @param out to write to
 * @param kv {@link KeyValue} to which to write
 * @throws IOException if there is an error writing
 */
public static void write(DataOutput out, KeyValue kv) throws IOException {
  if (kv instanceof IndexedKeyValue) {
    out.writeInt(INDEX_TYPE_LENGTH_MARKER);
    ((IndexedKeyValue) kv).writeData(out);
  } else {
      KeyValue.write(kv, out);
  }
}
 
Example 4
/**
 * Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
 * back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
 * @param out to write to
 * @param kv {@link KeyValue} to which to write
 * @throws IOException if there is an error writing
 */
public static void write(DataOutput out, KeyValue kv) throws IOException {
  if (kv instanceof IndexedKeyValue) {
    out.writeInt(INDEX_TYPE_LENGTH_MARKER);
    ((IndexedKeyValue) kv).writeData(out);
  } else {
    kv.write(out);
  }
}