summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java
blob: ba113c6076ca4c43541f3981d0ccf0e3064d3697 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.openslx.imagemaster.crcchecker;

import java.io.IOException;

public class ClassTest
{
	public static void main( String[] args ) throws IOException
	{
		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( filenameCrc );
		System.out.println( "Master sum: '" + f.getMasterSum() + "'" );
		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;
	}

}