final long p = this.getPosition(); // remember current position
// 1st aquire the buffers for both records
this.setPosition(r1);
final ByteBuffer b1 = BufferUtils.slice(this.next()); // Remember the buffer
this.setPosition(r2);
final ByteBuffer b2 = BufferUtils.slice(this.next()); // Remember the buffer
// Replace r2 first, as its replacement won't affect position of r1
this.setPosition(r2);
this.replace(b1);
// Lastly replace r1, it might affect r2 position, but r2 has already been
// replaced, so no big deal
this.setPosition(r1);
this.replace(b2);
/*
* Try to get back to roughly the same position, the position might only
* change if r1 < position < r2 and if r1.length != r2.length, otherwise the
* position should still end up on same record's start position
*/
this.seek(p);
this.autoflush.autoflushChange(b1.capacity() + b2.capacity());
}