DeletableFrameTupleAppender implements IAppendDeletableFrameTupleAccessor { @Override public void reOrganizeBuffer() { if (deletedSpace <= 0) { return; } reclaimDeletedEnding(); freeDataEndOffset = 0; int endOffset = 0; for (int i = 0; i < tupleCount; i++) { int startOffset = Math.abs(endOffset); endOffset = getTupleEndOffset(i); if (endOffset >= 0) { int length = endOffset - startOffset; assert ( length >= 0); if (freeDataEndOffset != startOffset) { System.arraycopy(array, startOffset, array, freeDataEndOffset, length); } freeDataEndOffset += length; } setTupleEndOffset(i, freeDataEndOffset); } setFreeDataEndOffset(freeDataEndOffset); deletedSpace = 0; setDeleteSpace(0); } DeletableFrameTupleAppender(RecordDescriptor recordDescriptor); @Override void clear(ByteBuffer buffer); @Override void reset(ByteBuffer buffer); @Override int append(IFrameTupleAccessor tupleAccessor, int tIndex); @Override void delete(int tupleIndex); @Override void reOrganizeBuffer(); @Override int getTotalFreeSpace(); @Override int getContiguousFreeSpace(); @Override int getFieldCount(); @Override int getFieldSlotsLength(); @Override int getFieldEndOffset(int tupleIndex, int fIdx); @Override int getFieldStartOffset(int tupleIndex, int fIdx); @Override int getFieldLength(int tupleIndex, int fIdx); @Override int getTupleLength(int tupleIndex); @Override int getTupleEndOffset(int tupleIndex); @Override int getTupleStartOffset(int tupleIndex); @Override int getAbsoluteFieldStartOffset(int tupleIndex, int fIdx); @Override int getTupleCount(); @Override ByteBuffer getBuffer();  }
@Test public void testReOrganizeBuffer() throws Exception { int count = 10; testDelete(); appender.reOrganizeBuffer(); ByteBuffer bufferRead = makeAFrame(cap, count, 0); DeletableFrameTupleAppender accessor = new DeletableFrameTupleAppender(recordDescriptor); accessor.reset(bufferRead); for (int i = 0; i < accessor.getTupleCount(); i++) { appender.append(accessor, i); } for (int i = 0; i < bufferRead.capacity(); i++) { assertEquals(bufferRead.get(i), appender.getBuffer().get(i)); } }