/** * Puts some data from one block into this block. * * @param offset The offset into this block of data to put the new data. * @param block The block containing the data to put into this block. * @param srcOffset The offset into the block parameter to find the source data. * @param length The number of bytes from the source block to copy over. */ public void put(int offset, Block block, int srcOffset, int length) { // There is only one writer so it is safe to change the position. bb.position(byteOffset + offset); bb.put(block.getSourceBuffer(srcOffset, length)); }
/** * Allocates a new block for dstBlockId, copies the contents of srcBlock to * it, releases srcBlock and returns the new Block. * * @param block The block to copy data from. This block will be set to the * destination block before returning, and acts as the return value. * @param dstBlockId the ID of the new Block to be allocated. */ public void copyBlock(Block block, long dstBlockId) { assert(block.getBlockId() >= 0) && (block.getBlockId() < nrBlocks); assert(dstBlockId >= 0) && (dstBlockId < nrBlocks); assert block.getBlockId() != dstBlockId; int byteOffset = block.getByteOffset(); ByteBuffer srcBuffer = block.getSourceBuffer(); srcBuffer.limit(byteOffset + blockSize); srcBuffer.position(byteOffset); long dstFileOffset = dstBlockId * blockSize; int dstRegionNr = (int) (dstFileOffset / stride); int dstByteOffset = (int) (dstFileOffset % stride); ByteBuffer dstBuffer = mappedByteBuffers[dstRegionNr]; dstBuffer.position(dstByteOffset); // Copy the bytes. dstBuffer.put(srcBuffer); block.init( dstBlockId, dstByteOffset, dstBuffer, srcByteBuffers[dstRegionNr], intBuffers[dstRegionNr], longBuffers[dstRegionNr] ); }