当前位置: 首页>>代码示例>>Java>>正文


Java KeyValueCodec.getEncoder方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.codec.KeyValueCodec.getEncoder方法的典型用法代码示例。如果您正苦于以下问题:Java KeyValueCodec.getEncoder方法的具体用法?Java KeyValueCodec.getEncoder怎么用?Java KeyValueCodec.getEncoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.codec.KeyValueCodec的用法示例。


在下文中一共展示了KeyValueCodec.getEncoder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEmptyWorks

import org.apache.hadoop.hbase.codec.KeyValueCodec; //导入方法依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  CountingOutputStream cos = new CountingOutputStream(baos);
  DataOutputStream dos = new DataOutputStream(cos);
  KeyValueCodec kvc = new KeyValueCodec();
  Codec.Encoder encoder = kvc.getEncoder(dos);
  encoder.flush();
  dos.close();
  long offset = cos.getCount();
  assertEquals(0, offset);
  CountingInputStream cis =
    new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
  DataInputStream dis = new DataInputStream(cis);
  Codec.Decoder decoder = kvc.getDecoder(dis);
  assertFalse(decoder.advance());
  dis.close();
  assertEquals(0, cis.getCount());
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:20,代码来源:TestKeyValueCodec.java

示例2: testOne

import org.apache.hadoop.hbase.codec.KeyValueCodec; //导入方法依赖的package包/类
@Test
public void testOne() throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  CountingOutputStream cos = new CountingOutputStream(baos);
  DataOutputStream dos = new DataOutputStream(cos);
  KeyValueCodec kvc = new KeyValueCodec();
  Codec.Encoder encoder = kvc.getEncoder(dos);
  final KeyValue kv =
    new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
  final long length = kv.getLength() + Bytes.SIZEOF_INT; 
  encoder.write(kv);
  encoder.flush();
  dos.close();
  long offset = cos.getCount();
  assertEquals(length, offset);
  CountingInputStream cis =
    new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
  DataInputStream dis = new DataInputStream(cis);
  Codec.Decoder decoder = kvc.getDecoder(dis);
  assertTrue(decoder.advance()); // First read should pull in the KV
  // Second read should trip over the end-of-stream  marker and return false
  assertFalse(decoder.advance());
  dis.close();
  assertEquals(length, cis.getCount());
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:26,代码来源:TestKeyValueCodec.java

示例3: testThree

import org.apache.hadoop.hbase.codec.KeyValueCodec; //导入方法依赖的package包/类
@Test
public void testThree() throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  CountingOutputStream cos = new CountingOutputStream(baos);
  DataOutputStream dos = new DataOutputStream(cos);
  KeyValueCodec kvc = new KeyValueCodec();
  Codec.Encoder encoder = kvc.getEncoder(dos);
  final KeyValue kv1 =
    new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("1"));
  final KeyValue kv2 =
    new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2"));
  final KeyValue kv3 =
    new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3"));
  final long length = kv1.getLength() + Bytes.SIZEOF_INT; 
  encoder.write(kv1);
  encoder.write(kv2);
  encoder.write(kv3);
  encoder.flush();
  dos.close();
  long offset = cos.getCount();
  assertEquals(length * 3, offset);
  CountingInputStream cis =
    new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
  DataInputStream dis = new DataInputStream(cis);
  Codec.Decoder decoder = kvc.getDecoder(dis);
  assertTrue(decoder.advance());
  KeyValue kv = (KeyValue)decoder.current();
  assertTrue(kv1.equals(kv));
  assertTrue(decoder.advance());
  kv = (KeyValue)decoder.current();
  assertTrue(kv2.equals(kv));
  assertTrue(decoder.advance());
  kv = (KeyValue)decoder.current();
  assertTrue(kv3.equals(kv));
  assertFalse(decoder.advance());
  dis.close();
  assertEquals((length * 3), cis.getCount());
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:39,代码来源:TestKeyValueCodec.java


注:本文中的org.apache.hadoop.hbase.codec.KeyValueCodec.getEncoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。