@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())); }
public void setTokenBytes(ByteRange source) { source.deepCopySubRangeTo(0, tokenLength, token, 0); }
public void setTokenBytes(ByteRange source) { source.deepCopySubRangeTo(0, tokenLength, token, 0); }
protected int appendTokenAndRepointByteRange(final ByteRange token, int inputTokenOffset) { int newOffset = tokensLength; int inputTokenLength = token.getLength() - inputTokenOffset; int newMinimum = tokensLength + inputTokenLength; tokens = ArrayUtils.growIfNecessary(tokens, newMinimum, 2 * newMinimum); token.deepCopySubRangeTo(inputTokenOffset, inputTokenLength, tokens, tokensLength); tokensLength += inputTokenLength; return newOffset; }
protected int appendTokenAndRepointByteRange(final ByteRange token, int inputTokenOffset) { int newOffset = tokensLength; int inputTokenLength = token.getLength() - inputTokenOffset; int newMinimum = tokensLength + inputTokenLength; tokens = ArrayUtils.growIfNecessary(tokens, newMinimum, 2 * newMinimum); token.deepCopySubRangeTo(inputTokenOffset, inputTokenLength, tokens, tokensLength); tokensLength += inputTokenLength; return newOffset; }
@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())); }
@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())); }