/** * Allocates a ByteBuffer which is filled with the contents of the * specified block. If the buffer is modified then the method {@link * #writeBlock} should be called to write the buffer back to the file but, * depending on the BlockFile implementation, changes to the ByteBuffer may * take effect even if {@link #writeBlock} is never called. * * @param objectPool the object pool to attempt to get objects from and * release objects to. * @param blockId the block to read into the ByteBuffer. * @return The read block. * @throws IOException if an I/O error occurs. */ public Block readBlock(ObjectPool objectPool, long blockId) throws IOException { Block block = blockFile.readBlock(objectPool, blockId); block.setBlockFile(this); return block; }
/** * Reads the reallocate block from blockFile. If the current reallocate buffer * already holds the reallocate block then nothing is done. If the reallocate * buffer contains a different block then it is released first. * * @param blockId The block number of the reallocate block. * @throws IOException if an I/O error occurs. */ private void readReallocateBlock(int blockId) throws IOException { if (reallocateBlock != null) { if (blockId == (int) reallocateBlock.getBlockId()) { return; } releaseReallocateBlock(); } reallocateBlock = findBlock(blockId); if (reallocateBlock == null) { reallocateBlock = blockFile.readBlock(objectPool, blockId); } reallocateBlockDirty = false; }
/** * Reads the tail block from blockFile. If the current tail buffer already * holds the tail block then nothing is done. If the tail buffer contains a * different block then it is freed first. * * @param blockId The block number to use as the tail buffer. * @throws IOException if an I/O error occurs. */ private void readTailBlock(int blockId) throws IOException { if (tailBlock != null) { if (blockId == (int) tailBlock.getBlockId()) { return; } releaseTailBlock(); } tailBlock = findBlock(blockId); if (tailBlock == null) { tailBlock = blockFile.readBlock(objectPool, blockId); } }
/** * Reads the head block from blockFile. If the current head buffer already * holds the head block then nothing is done. If the head buffer contains a * different block then it is freed first (writing it to the file). This is * similar to {@link #allocateHeadBlock} only it will not allocate a new * block from the file, and always reads the contents of the existing block * in the file. * * @param blockId The block number of the head block. * @throws IOException if an I/O error occurs. */ private void readHeadBlock(int blockId) throws IOException { if (headBlock != null) { if (blockId == (int) headBlock.getBlockId()) { return; } releaseHeadBlock(); } headBlock = findBlock(blockId); if (headBlock == null) { headBlock = blockFile.readBlock(objectPool, blockId); } headBlockDirty = false; }
nextHeadBlock = blockFile.readBlock(objectPool, nextHeadBlockId);