本文整理汇总了Java中org.apache.hadoop.hbase.util.PositionedByteRange.setPosition方法的典型用法代码示例。如果您正苦于以下问题:Java PositionedByteRange.setPosition方法的具体用法?Java PositionedByteRange.setPosition怎么用?Java PositionedByteRange.setPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.util.PositionedByteRange
的用法示例。
在下文中一共展示了PositionedByteRange.setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSkipSkippable
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
public void testSkipSkippable() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
for (OrderedString t : new OrderedString[] {
OrderedString.ASCENDING, OrderedString.DESCENDING
}) {
for (byte[] term : TERMINATORS) {
for (String val : VALUES_STRINGS) {
buff.setPosition(0);
DataType<String> type = new TerminatedWrapper<String>(t, term);
int expected = val.length() + 2 + term.length;
assertEquals(expected, type.encode(buff, val));
buff.setPosition(0);
assertEquals(expected, type.skip(buff));
assertEquals(expected, buff.getPosition());
}
}
}
}
示例2: testReadWrite
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
public void testReadWrite() {
for (int limit : limits) {
PositionedByteRange buff = new SimplePositionedMutableByteRange(limit);
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (byte[] val : VALUES) {
buff.setPosition(0);
DataType<byte[]> type = new FixedLengthWrapper<byte[]>(new RawBytes(ord), limit);
assertEquals(limit, type.encode(buff, val));
buff.setPosition(0);
byte[] actual = type.decode(buff);
assertTrue("Decoding output differs from expected",
Bytes.equals(val, 0, val.length, actual, 0, val.length));
buff.setPosition(0);
assertEquals(limit, type.skip(buff));
}
}
}
}
示例3: skip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
/**
* Skip {@code src}'s position forward over one encoded value.
* @param src the buffer containing the encoded value.
* @return number of bytes skipped.
* @throws IllegalArgumentException when the terminator sequence is not found.
*/
@Override
public int skip(PositionedByteRange src) {
if (wrapped.isSkippable()) {
int ret = wrapped.skip(src);
src.setPosition(src.getPosition() + term.length);
return ret + term.length;
} else {
// find the terminator position
final int start = src.getPosition();
int skipped = terminatorPosition(src);
if (-1 == skipped) throw new IllegalArgumentException("Terminator sequence not found.");
skipped += term.length;
src.setPosition(skipped);
return skipped - start;
}
}
示例4: testSkipNonSkippable
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
public void testSkipNonSkippable() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(12);
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (byte[] term : TERMINATORS) {
for (byte[] val : VALUES_BYTES) {
buff.setPosition(0);
DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(ord), term);
int expected = type.encode(buff, val);
buff.setPosition(0);
assertEquals(expected, type.skip(buff));
assertEquals(expected, buff.getPosition());
}
}
}
}
示例5: testReadWrite
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
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 SimplePositionedMutableByteRange(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());
}
}
}
示例6: testReadWriteNonSkippable
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
public void testReadWriteNonSkippable() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(12);
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (byte[] term : TERMINATORS) {
for (byte[] val : VALUES_BYTES) {
buff.setPosition(0);
DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(ord), term);
assertEquals(val.length + term.length, type.encode(buff, val));
buff.setPosition(0);
assertArrayEquals(val, type.decode(buff));
assertEquals(val.length + term.length, buff.getPosition());
}
}
}
}
示例7: skip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Override
public int skip(PositionedByteRange src) {
src.setPosition(src.getPosition() + Bytes.SIZEOF_BYTE);
return Bytes.SIZEOF_BYTE;
}
示例8: encode
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
/**
* Write instance {@code val} into buffer {@code dst}.
* @throws IllegalArgumentException when the encoded representation of
* {@code val} contains the {@code term} sequence.
*/
@Override
public int encode(PositionedByteRange dst, T val) {
final int start = dst.getPosition();
int written = wrapped.encode(dst, val);
PositionedByteRange b = dst.shallowCopy();
b.setLength(dst.getPosition());
b.setPosition(start);
if (-1 != terminatorPosition(b)) {
dst.setPosition(start);
throw new IllegalArgumentException("Encoded value contains terminator sequence.");
}
dst.put(term);
return written + term.length;
}
示例9: testRoundTrip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
/**
* Basic test to verify utility methods in {@link PBType} and delegation to protobuf works.
*/
@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)));
}
示例10: testEncodeDecode
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
public void testEncodeDecode() {
Integer intVal = Integer.valueOf(10);
String strVal = "hello";
PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
SampleUnion1 type = new SampleUnion1();
type.encode(buff, intVal);
buff.setPosition(0);
assertTrue(0 == intVal.compareTo(type.decodeA(buff)));
buff.setPosition(0);
type.encode(buff, strVal);
buff.setPosition(0);
assertTrue(0 == strVal.compareTo(type.decodeB(buff)));
}
示例11: testSkip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Test
public void testSkip() {
Integer intVal = Integer.valueOf(10);
String strVal = "hello";
PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
SampleUnion1 type = new SampleUnion1();
int len = type.encode(buff, intVal);
buff.setPosition(0);
assertEquals(len, type.skip(buff));
buff.setPosition(0);
len = type.encode(buff, strVal);
buff.setPosition(0);
assertEquals(len, type.skip(buff));
}
示例12: encode
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Override
public int encode(PositionedByteRange dst, CellProtos.Cell val) {
CodedOutputStream os = outputStreamFromByteRange(dst);
try {
int before = os.spaceLeft(), after, written;
val.writeTo(os);
after = os.spaceLeft();
written = before - after;
dst.setPosition(dst.getPosition() + written);
return written;
} catch (IOException e) {
throw new RuntimeException("Error while encoding type.", e);
}
}
示例13: skip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Override
public int skip(PositionedByteRange src) {
src.setPosition(src.getPosition() + Bytes.SIZEOF_INT);
return Bytes.SIZEOF_INT;
}
示例14: skip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Override
public int skip(PositionedByteRange src) {
src.setPosition(src.getPosition() + Bytes.SIZEOF_DOUBLE);
return Bytes.SIZEOF_DOUBLE;
}
示例15: skip
import org.apache.hadoop.hbase.util.PositionedByteRange; //导入方法依赖的package包/类
@Override
public int skip(PositionedByteRange src) {
src.setPosition(src.getPosition() + this.length);
return this.length;
}