Package org.apache.hadoop.hbase.util

Examples of org.apache.hadoop.hbase.util.PositionedByteRange


  public void testReadWrite() {
    for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
      RawString type =
          Order.ASCENDING == ord ? RawString.ASCENDING : RawString.DESCENDING;
      for (String val : VALUES) {
        PositionedByteRange buff = new SimplePositionedByteRange(Bytes.toBytes(val).length);
        assertEquals(buff.getLength(), type.encode(buff, val));
        byte[] expected = Bytes.toBytes(val);
        ord.apply(expected);
        assertArrayEquals(expected, buff.getBytes());
        buff.setPosition(0);
        assertEquals(val, type.decode(buff));
        buff.setPosition(0);
        assertEquals(buff.getLength(), type.skip(buff));
        assertEquals(buff.getLength(), buff.getPosition());
      }
    }
  }
View Full Code Here


      throw new IllegalArgumentException("Not enough buffer remaining. src.offset: "
          + src.getOffset() + " src.length: " + src.getLength() + " src.position: "
          + src.getPosition() + " max length: " + length);
    }
    // create a copy range limited to length bytes. boo.
    PositionedByteRange b = new SimplePositionedByteRange(length);
    src.get(b.getBytes());
    return base.decode(b);
  }
View Full Code Here

  protected OrderedNumeric(Order order) { super(order); }

  @Override
  public int encodedLength(Number val) {
    // TODO: this could be done better.
    PositionedByteRange buff = new SimplePositionedByteRange(100);
    return encode(buff, val);
  }
View Full Code Here

  @Test
  public void testRoundTrip() {
    final Cell cell = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"),
      Bytes.toBytes("qual"), Bytes.toBytes("val"));
    CellProtos.Cell c = ProtobufUtil.toCell(cell), decoded;
    PositionedByteRange pbr = new SimplePositionedByteRange(c.getSerializedSize());
    pbr.setPosition(0);
    int encodedLength = CODEC.encode(pbr, c);
    pbr.setPosition(0);
    decoded = CODEC.decode(pbr);
    assertEquals(encodedLength, pbr.getPosition());
    assertTrue(CellComparator.equals(cell, ProtobufUtil.toCell(decoded)));
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.util.PositionedByteRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.