Object data = this.dataFile.read( entry.getValue() ); if ( data == null )
Object data = this.dataFile.read( entry.getValue() ); if ( data == null )
if ( ded != null ) object = this.dataFile.read( ded );
if ( ded != null ) object = this.dataFile.read( ded );
String result = (String) disk.read( blocks );
String result = (String) disk.read( blocks );
/** * 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 ); }
/** * Verify that the block disk can handle a big string. * <p> * @throws Exception */ public void testWriteAndRead_BigString2() throws Exception { // SETUP String fileName = "testWriteAndRead_BigString"; File file = new File( rafDir, fileName + ".data" ); file.delete(); int blockSizeBytes = 47;//4096;//1024; BlockDisk disk = new BlockDisk( file, blockSizeBytes, new StandardSerializer() ); String string = "abcdefghijklmnopqrstuvwxyz1234567890"; string += string; string += string; // DO WORK int[] blocks = disk.write( string ); String result = (String) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", string, result ); }
/** * 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 ); }
/** * Verify that the block disk can handle a big string. * <p> * @throws Exception */ public void testWriteAndRead_BigString2() throws Exception { // SETUP String fileName = "testWriteAndRead_BigString"; File file = new File( rafDir, fileName + ".data" ); file.delete(); int blockSizeBytes = 47;//4096;//1024; BlockDisk disk = new BlockDisk( file, blockSizeBytes, new StandardSerializer() ); String string = "abcdefghijklmnopqrstuvwxyz1234567890"; string += string; string += string; // DO WORK int[] blocks = disk.write( string ); String result = (String) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", string, result ); } }
byte[] result = (byte[]) disk.read( blocks );
byte[] result = (byte[]) disk.read( blocks );
/** * Test writing and reading elements that do not fit within a single block. * <p> * @throws Exception */ public void testWriteAndReadMultipleMultiBlockElement() throws Exception { // SETUP String fileName = "testWriteAndReadSingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int numBlocksPerElement = 4; int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement ); int numElements = 100; for ( int i = 0; i < numElements; i++ ) { int[] blocks = disk.write( new byte[bytes] ); byte[] result = (byte[]) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", new byte[bytes].length, result.length ); assertEquals( "Wrong number of blocks returned.", numBlocksPerElement, blocks.length ); } }
/** * Test writing and reading elements that do not fit within a single block. * <p> * @throws Exception */ public void testWriteAndReadMultipleMultiBlockElement() throws Exception { // SETUP String fileName = "testWriteAndReadSingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int numBlocksPerElement = 4; int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement ); int numElements = 100; for ( int i = 0; i < numElements; i++ ) { int[] blocks = disk.write( new byte[bytes] ); byte[] result = (byte[]) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", new byte[bytes].length, result.length ); assertEquals( "Wrong number of blocks returned.", numBlocksPerElement, blocks.length ); } }