diff options
author | Nils Schwabe | 2014-07-25 11:32:28 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-25 11:32:28 +0200 |
commit | f6ce907f69cc497e4556f90e74ea9876fe71274d (patch) | |
tree | 349602d70396214d12dff17e2947a6bb8dd014f2 /src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java | |
parent | Merge branch 'master' of git.openslx.org:bwlp/master-sync-shared (diff) | |
download | master-sync-shared-f6ce907f69cc497e4556f90e74ea9876fe71274d.tar.gz master-sync-shared-f6ce907f69cc497e4556f90e74ea9876fe71274d.tar.xz master-sync-shared-f6ce907f69cc497e4556f90e74ea9876fe71274d.zip |
[CRCFile] Add checks to prevent null pointer exception
[ClassTest] Made pretty
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java b/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java index 7d905a3..37f7fb2 100644 --- a/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java +++ b/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java @@ -6,35 +6,36 @@ public class ClassTest { public static void main( String[] args ) throws IOException { - String filename = "/home/nils/win98-dp-demo-de.vmdk.r1"; - final int bs = 16 * 1024 * 1024; + if ( args.length != 2 ) { + System.out.println( "Usage: filename crcfilename" ); + return; + } + String filename = args[0]; + String filenameCrc = args[1]; + final int blockSize = 16 * 1024 * 1024; - CRCFile f = new CRCFile( filename.concat( ".crc" ) ); - System.out.println( f.getMasterSum() ); + CRCFile f = new CRCFile( filenameCrc ); + System.out.println( "Master sum: '" + f.getMasterSum() + "'" ); System.out.println( f.getCrcSums() ); - System.out.println( f.isValid() ); - - System.out.println( CRCFile.sumsAreValid( f.getCrcSums() ) ); - - ImageFile i = new ImageFile( filename, bs ); - - CRCChecker c = new CRCChecker( i, f ); - System.out.println( c.checkBlock( 0 ) ); - System.out.println( c.checkBlock( 1 ) ); - System.out.println( c.checkBlock( 2 ) ); - System.out.println( c.checkBlock( 3 ) ); - System.out.println( c.checkBlock( 4 ) ); - System.out.println( c.checkBlock( 5 ) ); - System.out.println( c.checkBlock( 6 ) ); - System.out.println( c.checkBlock( 7 ) ); - System.out.println( c.checkBlock( 8 ) ); - System.out.println( c.checkBlock( 9 ) ); - System.out.println( c.checkBlock( 10 ) ); - System.out.println( c.checkBlock( 11 ) ); - System.out.println( c.checkBlock( 12 ) ); - System.out.println( c.checkBlock( 13 ) ); - System.out.println( c.checkBlock( 14 ) ); - System.out.println( c.checkBlock( 15 ) ); - c.done(); + System.out.println( "CRC file is '" + ( ( f.isValid() ) ? "valid" : "invalid" ) + "'" ); + + ImageFile imageFile = new ImageFile( filename, blockSize ); + CRCChecker crcFile = new CRCChecker( imageFile, f ); + + int blocks = getNumberOfBlocks( imageFile.length(), blockSize ); + for ( int i = 0; i < blocks; i++ ) { + System.out.println( "Block\t" + i + "\tis '" + ( ( crcFile.checkBlock( i ) ) ? "valid" : "invalid" ) + "'" ); + } + + crcFile.done(); } + + public static int getNumberOfBlocks( long fileSize, int blockSize ) + { + int blocks = (int) ( fileSize / blockSize ); + if ( fileSize % blockSize != 0 ) + blocks++; + return blocks; + } + } |