BinaryDataSegment extends AbstractDataSegment { public final int deserialize (final ByteBuffer src, final int len) { resizeBuffer(src.remaining(), false); dataBuffer.rewind(); 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 testDeserializeBuffer () { final BinaryDataSegment dataSegment = new BinaryDataSegment(CHUNK_SIZE); assertNotNull(dataSegment); assertEquals(0, dataSegment.getLength()); final ByteBuffer testBuffer = ByteBuffer.wrap(TEST_CASE_1_ARRAY); dataSegment.deserialize(testBuffer, TEST_CASE_1_ARRAY.length); 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 testSerializeBuffer () { final BinaryDataSegment dataSegment = new BinaryDataSegment(CHUNK_SIZE); assertNotNull(dataSegment); assertEquals(0, dataSegment.getLength()); final ByteBuffer testBuffer = ByteBuffer.wrap(TEST_CASE_1_ARRAY); dataSegment.deserialize(testBuffer, TEST_CASE_1_ARRAY.length); assertEquals(TEST_CASE_1_ARRAY.length, dataSegment.getLength()); final ByteBuffer expectedResult = ByteBuffer.wrap(TEST_CASE_1_ARRAY_LONG); dataSegment.dataBuffer.rewind(); final ByteBuffer exportedDataSegment = ByteBuffer.allocate(AbstractDataSegment.getTotalLength(dataSegment.getLength())); dataSegment.serialize(exportedDataSegment, 0); exportedDataSegment.rewind(); assertTrue(expectedResult.equals(exportedDataSegment)); }
@Test public final void testClear () { final BinaryDataSegment dataSegment = new BinaryDataSegment(CHUNK_SIZE); assertNotNull(dataSegment); assertEquals(0, dataSegment.getLength()); final ByteBuffer testBuffer = ByteBuffer.wrap(TEST_CASE_1_ARRAY); dataSegment.deserialize(testBuffer, TEST_CASE_1_ARRAY.length); assertEquals(TEST_CASE_1_ARRAY.length, dataSegment.getLength()); dataSegment.clear(); assertNotNull(dataSegment); assertEquals(0, dataSegment.getLength()); }