public Record(byte[] key, byte[] value) { this.key = key ; this.value = value ; if ( SystemIndex.Checking ) { if ( value != null && value.length == 0 ) throw new RecordException("Zero length value") ; } }
static void checkCompatible(Record record1, Record record2) { if ( ! compatible(record1, record2, true) ) throw new RecordException(format("Incompatible: %s, %s", record1, record2)) ; }
static void checkKeyCompatible(Record record1, Record record2) { if ( ! compatible(record1, record2, false) ) throw new RecordException(format("Incompatible: %s, %s", record1, record2)) ; }
@Override public RecordBufferPage createFromBlock(Block block, BlockType blkType) { if ( blkType != BlockType.RECORD_BLOCK ) throw new RecordException("Not RECORD_BLOCK: " + blkType) ; // Initially empty RecordBufferPage rb = RecordBufferPage.createBlank(block, factory) ; return rb ; }
protected BufferBase(ByteBuffer bb, int slotLen, int num) { if ( CheckBuffer ) { if ( ! bb.order().equals(NetworkOrder) || !bb.hasArray() ) throw new RecordException("Duff buffer (byte order is not network order)") ; if ( bb.limit() == 0 ) throw new RecordException("Duff buffer (zero length byte buffer)") ; int size = bb.limit() ; int slots = size/slotLen ; if ( size%slotLen != 0 ) throw new RecordException(format("Misaligned buffer: size=%d, keyLen=%d",size, slotLen)) ; if ( slots < num ) throw new RecordException(format("Wrong size: slots=%d, len=%d", slots, num)) ; } this.bb = bb ; this.slotLen = slotLen ; this.numSlot = num ; this.maxSlot = bb.limit()/slotLen ; if ( ! bb.isReadOnly() && NullOut ) clear(numSlot, maxSlot-numSlot) ; }
final public void copy(int srcIdx, BufferBase dst, int dstIdx, int len) { if ( len == 0 ) return ; // Check end index is inside the buffer. checkBounds(srcIdx+len-1, maxSlot) ; BufferBase src = this ; // Clarity if ( dst.numSlot < dstIdx-1 ) // Allow copy to be just off the end of dst. throw new IllegalArgumentException(format("copy: Out of bounds: dstIdx=%d, dst size=%d", dstIdx, dst.numSlot)) ; if ( src.slotLen != dst.slotLen ) throw new RecordException(format("copy: records of differnt sizes: %d, %d",src.slotLen, dst.slotLen)) ; // How do we set the numRec in dst? max(dstIdx+len, old count) ByteBufferLib.bbcopy(src.bb, srcIdx, dst.bb, dstIdx, len, slotLen) ; dst.numSlot = Math.max(dstIdx+len, dst.numSlot) ; }