int numBlocksNeeded = calculateTheNumberOfBlocksNeeded(data); int[] blocks = allocateBlocks(numBlocksNeeded); long position = calculateByteOffsetForBlockAsLong(blocks[i]);
data = readBlock( blockNumbers[0] ); ByteArrayOutputStream baos = new ByteArrayOutputStream(getBlockSizeBytes()); byte[] chunk = readBlock( blockNumbers[i] ); baos.write(chunk);
Object data = this.dataFile.read( entry.getValue() ); if ( data == null )
int numBlocksNeeded = calculateTheNumberOfBlocksNeeded(data); int[] blocks = allocateBlocks(numBlocksNeeded); long position = calculateByteOffsetForBlock(blocks[i]);
/** * Test writing an element that takes two blocks. * <p> * @throws Exception */ public void testWrite_DoubleBlockElement() throws Exception { // SETUP String fileName = "testWriteDoubleBlockElement"; File file = new File( rafDir, fileName + ".data" ); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK // byte arrays encur 27 bytes of serialization overhead. int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), 2 ); int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", 2, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", 2, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing a null object within a single block size. * <p> * @throws Exception */ public void testWrite_NullBlockElement() throws Exception { // SETUP String fileName = "testWrite_NullBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int[] blocks = disk.write( null ); // VERIFY assertEquals( "Wrong number of blocks recorded.", 1, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", 1, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing and reading an element within a single block size. * <p> * @throws Exception */ public void testWriteAndRead_SingleBlockElement() throws Exception { // SETUP String fileName = "testWriteAndRead_SingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int bytes = 1 * 1024; int[] blocks = disk.write( new byte[bytes] ); byte[] result = (byte[]) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", new byte[bytes].length, result.length ); }
Long.valueOf(this.dataFile != null ? this.dataFile.length() : -1L) ) ); Integer.valueOf(this.dataFile.getBlockSizeBytes()) ) ); elems.add(new StatElement<Integer>( "Number Of Blocks", Integer.valueOf(this.dataFile.getNumberOfBlocks()) ) ); elems.add(new StatElement<Long>( "Average Put Size Bytes", Long.valueOf(this.dataFile.getAveragePutSizeBytes()) ) ); elems.add(new StatElement<Integer>( "Empty Blocks", Integer.valueOf(this.dataFile.getEmptyBlocks()) ) );
/** * Verify that it says we need two blocks if the total size will fit. * <p> * @throws Exception */ public void testCalculateBlocksNeededDouble() throws Exception { // SETUP String fileName = "testCalculateBlocksNeededDouble"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int result = disk.calculateTheNumberOfBlocksNeeded( new byte[disk.getBlockSizeBytes() * 2 - ( 2 * BlockDisk.HEADER_SIZE_BYTES )] ); // Verify assertEquals( "Wrong number of blocks", 2, result ); }
BlockDisk blockDisk = new BlockDisk(file, 200, elementSerializer); int numBlocksNeeded = blockDisk.calculateTheNumberOfBlocksNeeded(data); byte[][] chunks = blockDisk.getBlockChunks(data, numBlocksNeeded);
this.dataFile.freeBlocks( old ); int[] blocks = this.dataFile.write( element );
public void testJCS156() throws Exception { // SETUP String fileName = "testJCS156"; File file = new File( rafDir, fileName + ".data" ); file.delete(); int blockSizeBytes = 4096; BlockDisk disk = new BlockDisk( file, blockSizeBytes, new StandardSerializer() ); long offset = disk.calculateByteOffsetForBlockAsLong(Integer.MAX_VALUE); assertTrue("Must not wrap round", offset > 0); assertEquals(Integer.MAX_VALUE*4096L,offset); file.delete(); } }
/** * Add these blocks to the emptyBlock list. * <p> * @param blocksToFree */ protected void freeBlocks( int[] blocksToFree ) { this.dataFile.freeBlocks( blocksToFree ); }
long fileLength = fc.size(); long position = calculateByteOffsetForBlockAsLong( block );
/** * Test writing an element that takes 128 blocks. There was a byte in a for loop that limited the number to 127. I fixed this. * <p> * @throws Exception */ public void testWrite_128BlockElement() throws Exception { // SETUP int numBlocks = 128; String fileName = "testWrite_128BlockElement"; File file = new File( rafDir, fileName + ".data" ); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK // byte arrays encur 27 bytes of serialization overhead. int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocks ); int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", numBlocks, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", numBlocks, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing an element within a single block size. * <p> * @throws Exception */ public void testWrite_SingleBlockElement() throws Exception { // SETUP String fileName = "testWrite_SingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int bytes = 1 * 1024; int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", 1, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", 1, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing and reading an element within a single block size. * <p> * @throws Exception */ public void testWriteAndRead_SingleBlockElement() throws Exception { // SETUP String fileName = "testWriteAndRead_SingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int bytes = 1 * 1024; int[] blocks = disk.write( new byte[bytes] ); byte[] result = (byte[]) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", new byte[bytes].length, result.length ); }
elems.add(new StatElement<Long>( "Data File Length", Long.valueOf(this.dataFile.length()) ) ); Integer.valueOf(this.dataFile.getBlockSizeBytes()) ) ); elems.add(new StatElement<Integer>( "Number Of Blocks", Integer.valueOf(this.dataFile.getNumberOfBlocks()) ) ); elems.add(new StatElement<Long>( "Average Put Size Bytes", Long.valueOf(this.dataFile.getAveragePutSizeBytes()) ) ); elems.add(new StatElement<Integer>( "Empty Blocks", Integer.valueOf(this.dataFile.getEmptyBlocks()) ) );