/** * @return true when {@code range} is of zero length, false otherwise. */ public static boolean isEmpty(ByteRange range) { return range == null || range.getLength() == 0; }
public static void write(OutputStream os, ByteRange byteRange, int byteRangeInnerOffset) throws IOException { os.write(byteRange.getBytes(), byteRange.getOffset() + byteRangeInnerOffset, byteRange.getLength() - byteRangeInnerOffset); }
public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) { int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset); final byte[] lbytes = left.getBytes(), rbytes = right.getBytes(); final int loffset = left.getOffset(), roffset = right.getOffset(); for (int i = 0; i < maxCompares; ++i) { if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) { return i; } } return maxCompares; }
public static void write(OutputStream os, ByteRange byteRange) throws IOException { os.write(byteRange.getBytes(), byteRange.getOffset(), byteRange.getLength()); }
/** * Bitwise comparison of each byte in the array. Unsigned comparison, not * paying attention to java's signed bytes. */ @Override public int compareTo(ByteRange other) { return Bytes.compareTo(bytes, offset, length, other.getBytes(), other.getOffset(), other.getLength()); }
@Override public ReturnCode filterCell(final Cell cell) throws IOException { if (curFamily.getBytes() == null || !(PrivateCellUtil.matchingFamily(cell, curFamily.getBytes(), curFamily.getOffset(), curFamily.getLength()))) { curFamily.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()); // For this family, all the columns can have max of curFamilyMaxVersions versions. No need to // consider the older versions for visibility label check. // Ideally this should have been done at a lower layer by HBase (?) curFamilyMaxVersions = cfVsMaxVersions.get(curFamily); // Family is changed. Just unset curQualifier. curQualifier.unset(); } if (curQualifier.getBytes() == null || !(PrivateCellUtil.matchingQualifier(cell, curQualifier.getBytes(), curQualifier.getOffset(), curQualifier.getLength()))) { curQualifier.set(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); curQualMetVersions = 0; } curQualMetVersions++; if (curQualMetVersions > curFamilyMaxVersions) { return ReturnCode.SKIP; } return this.expEvaluator.evaluate(cell) ? ReturnCode.INCLUDE : ReturnCode.SKIP; }
@Test public void testEmpty(){ Assert.assertTrue(SimpleMutableByteRange.isEmpty(null)); ByteRange r = new SimpleMutableByteRange(); Assert.assertTrue(SimpleMutableByteRange.isEmpty(r)); Assert.assertTrue(r.isEmpty()); r.set(new byte[0]); Assert.assertEquals(0, r.getBytes().length); Assert.assertEquals(0, r.getOffset()); Assert.assertEquals(0, r.getLength()); Assert.assertTrue(Bytes.equals(new byte[0], r.deepCopyToNewArray())); Assert.assertEquals(0, r.compareTo(new SimpleMutableByteRange(new byte[0], 0, 0))); Assert.assertEquals(0, r.hashCode()); }
@Test public void testBasics() { ByteRange r = new SimpleMutableByteRange(new byte[] { 1, 3, 2 }); Assert.assertFalse(SimpleMutableByteRange.isEmpty(r)); Assert.assertNotNull(r.getBytes());//should be empty byte[], but could change this behavior Assert.assertEquals(3, r.getBytes().length); Assert.assertEquals(0, r.getOffset()); Assert.assertEquals(3, r.getLength()); //cloning (deep copying) Assert.assertTrue(Bytes.equals(new byte[]{1, 3, 2}, r.deepCopyToNewArray())); Assert.assertNotSame(r.getBytes(), r.deepCopyToNewArray()); //hash code Assert.assertTrue(r.hashCode() > 0); Assert.assertEquals(r.hashCode(), r.deepCopy().hashCode()); //copying to arrays byte[] destination = new byte[]{-59};//junk r.deepCopySubRangeTo(2, 1, destination, 0); Assert.assertTrue(Bytes.equals(new byte[]{2}, destination)); //set length r.setLength(1); Assert.assertTrue(Bytes.equals(new byte[]{1}, r.deepCopyToNewArray())); r.setLength(2);//verify we retained the 2nd byte, but dangerous in real code Assert.assertTrue(Bytes.equals(new byte[]{1, 3}, r.deepCopyToNewArray())); }
/** * @return true when {@code range} is of zero length, false otherwise. */ public static boolean isEmpty(ByteRange range) { return range == null || range.getLength() == 0; }
/** * @return true when {@code range} is of zero length, false otherwise. */ public static boolean isEmpty(ByteRange range) { return range == null || range.getLength() == 0; }
/****************** writing back to byte[]'s *************************/ public byte[] getNewByteArray() { byte[] arrayToFill = new byte[tokenStartOffset + token.getLength()]; fillInBytes(arrayToFill); return arrayToFill; }
public static void write(OutputStream os, ByteRange byteRange, int byteRangeInnerOffset) throws IOException { os.write(byteRange.getBytes(), byteRange.getOffset() + byteRangeInnerOffset, byteRange.getLength() - byteRangeInnerOffset); }
public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) { int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset); final byte[] lbytes = left.getBytes(), rbytes = right.getBytes(); final int loffset = left.getOffset(), roffset = right.getOffset(); for (int i = 0; i < maxCompares; ++i) { if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) { return i; } } return maxCompares; }
public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) { int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset); final byte[] lbytes = left.getBytes(), rbytes = right.getBytes(); final int loffset = left.getOffset(), roffset = right.getOffset(); for (int i = 0; i < maxCompares; ++i) { if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) { return i; } } return maxCompares; }
public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) { int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset); final byte[] lbytes = left.getBytes(), rbytes = right.getBytes(); final int loffset = left.getOffset(), roffset = right.getOffset(); for (int i = 0; i < maxCompares; ++i) { if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) { return i; } } return maxCompares; }
public void fillInBytes(byte[] arrayToFill) { for (int i = 0; i < token.getLength(); ++i) { arrayToFill[tokenStartOffset + i] = token.get(i); } if (parent != null) { parent.fillInBytes(arrayToFill); } }
/** * Bitwise comparison of each byte in the array. Unsigned comparison, not * paying attention to java's signed bytes. */ @Override public int compareTo(ByteRange other) { return Bytes.compareTo(bytes, offset, length, other.getBytes(), other.getOffset(), other.getLength()); }
/** * Bitwise comparison of each byte in the array. Unsigned comparison, not * paying attention to java's signed bytes. */ @Override public int compareTo(ByteRange other) { return Bytes.compareTo(bytes, offset, length, other.getBytes(), other.getOffset(), other.getLength()); }