BinaryDataSegment extends AbstractDataSegment { public final int append (final ByteBuffer src, final int len) { if (src == null) { throw new NullPointerException(); } dataBuffer.position(length); resizeBuffer(length + len, true); transferBytes(src, dataBuffer, len); return dataBuffer.limit(); } BinaryDataSegment(final int chunkSize); final int deserialize(final ByteBuffer src, final int len); final int append(final ByteBuffer src, final int len);  }
@Test public final void testAppendBuffer () { final ByteBuffer testBuffer = ByteBuffer.wrap(TEST_CASE_1_ARRAY); assertNotNull(testBuffer); final BinaryDataSegment dataSegment = new BinaryDataSegment(CHUNK_SIZE); dataSegment.append(testBuffer, testBuffer.remaining()); assertNotNull(dataSegment); assertEquals(TEST_CASE_1_ARRAY.length, dataSegment.getLength()); final ByteBuffer expectedResult = ByteBuffer.wrap(TEST_CASE_1_ARRAY_LONG); dataSegment.dataBuffer.rewind(); assertTrue(expectedResult.equals(dataSegment.dataBuffer)); }
@Test public final void testEquals () { final ByteBuffer testBuffer = ByteBuffer.allocate(TEST_CASE_1_ARRAY.length); assertNotNull(testBuffer); testBuffer.put(TEST_CASE_1_ARRAY); testBuffer.rewind(); final BinaryDataSegment dataSegment = new BinaryDataSegment(CHUNK_SIZE); dataSegment.append(testBuffer, testBuffer.limit()); assertNotNull(dataSegment); assertEquals(5, dataSegment.getLength()); final BinaryDataSegment anotherDataSegment = new BinaryDataSegment(CHUNK_SIZE); testBuffer.rewind(); anotherDataSegment.append(testBuffer, testBuffer.limit()); assertNotNull(anotherDataSegment); assertEquals(5, anotherDataSegment.getLength()); assertTrue(dataSegment.equals(anotherDataSegment)); }