diff --git hbase-common/src/main/java/org/apache/hadoop/hbase/util/PositionedByteRange.java hbase-common/src/main/java/org/apache/hadoop/hbase/util/PositionedByteRange.java index 7d49538..cf370d6 100644 --- hbase-common/src/main/java/org/apache/hadoop/hbase/util/PositionedByteRange.java +++ hbase-common/src/main/java/org/apache/hadoop/hbase/util/PositionedByteRange.java @@ -60,6 +60,39 @@ public interface PositionedByteRange extends ByteRange { public int getRemaining(); /** + * Limits the byte range upto a specified value. Limit cannot be greater than + * capacity + * + * @param limit + * @return + */ + public PositionedByteRange setLimit(int limit); + + /** + * Return the current limit + * + * @return + */ + public int getLimit(); + + /** + * Returns a copy of the ByteRange but the position is reset to initial + * position + * + * @return + */ + public PositionedByteRange asReadOnlyByteRange(); + + /** + * Helpful in clearing the bytes allocated off heap + * + * @throws Exception + */ + public void clean() throws Exception; + + /** + + /** * Retrieve the next byte from this range without incrementing position. */ public byte peek(); diff --git hbase-common/src/main/java/org/apache/hadoop/hbase/util/SimplePositionedByteRange.java hbase-common/src/main/java/org/apache/hadoop/hbase/util/SimplePositionedByteRange.java index c13539d..925114d 100644 --- hbase-common/src/main/java/org/apache/hadoop/hbase/util/SimplePositionedByteRange.java +++ hbase-common/src/main/java/org/apache/hadoop/hbase/util/SimplePositionedByteRange.java @@ -49,6 +49,8 @@ public class SimplePositionedByteRange extends SimpleByteRange implements Positi */ private int position = 0; + private int limit = 0; + /** * Create a new {@code PositionedByteRange} lacking a backing array and with * an undefined viewport. @@ -97,6 +99,7 @@ public class SimplePositionedByteRange extends SimpleByteRange implements Positi public PositionedByteRange set(int capacity) { this.position = 0; super.set(capacity); + this.limit = capacity; return this; } @@ -104,6 +107,7 @@ public class SimplePositionedByteRange extends SimpleByteRange implements Positi public PositionedByteRange set(byte[] bytes) { this.position = 0; super.set(bytes); + this.limit = bytes.length; return this; } @@ -111,6 +115,7 @@ public class SimplePositionedByteRange extends SimpleByteRange implements Positi public PositionedByteRange set(byte[] bytes, int offset, int length) { this.position = 0; super.set(bytes, offset, length); + limit = length; return this; } @@ -258,4 +263,28 @@ public class SimplePositionedByteRange extends SimpleByteRange implements Positi clone.position = this.position; return clone; } + + @Override + public PositionedByteRange setLimit(int limit) { + this.limit = limit; + return this; + } + + @Override + public int getLimit() { + return this.limit; + } + + @Override + public PositionedByteRange asReadOnlyByteRange() { + SimplePositionedByteRange clone = new SimplePositionedByteRange(bytes, offset, length); + clone.position = 0; + clone.limit = this.limit; + return clone; + } + + @Override + public void clean() throws Exception { + // Do nothing here + } }