diff options
| author | Nils Schwabe | 2014-07-29 15:55:52 +0200 |
|---|---|---|
| committer | Nils Schwabe | 2014-07-29 15:55:52 +0200 |
| commit | 6ea561385a291bb78077c368b1df5f997e11d80e (patch) | |
| tree | a961358dea1ba3f45cd0fdd8e956910ada8a2a53 /src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java | |
| parent | Change type of range to long so that files larger than 2 GiB are supported (diff) | |
| download | master-sync-shared-6ea561385a291bb78077c368b1df5f997e11d80e.tar.gz master-sync-shared-6ea561385a291bb78077c368b1df5f997e11d80e.tar.xz master-sync-shared-6ea561385a291bb78077c368b1df5f997e11d80e.zip | |
Rename classes and methods to fit camelCase
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java')
| -rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java deleted file mode 100644 index d0384a6..0000000 --- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.openslx.imagemaster.crcchecker; - -import java.io.IOException; -import java.util.zip.CRC32; - -public class CRCChecker -{ - private static final int blockSize = 16 * 1024 * 1024; - - private ImageFile imageFile; - private CRCFile crcFile; - - private byte[] block = new byte[ blockSize ]; // array that is used to read the blocks - - /** - * Initialize a crc checker with an image file and a crc file. - * - * @param imageFile The image file to check - * @param crcFile The crc file to check against - */ - public CRCChecker( ImageFile imageFile, CRCFile crcFile ) - { - this.imageFile = imageFile; - this.crcFile = crcFile; - } - - public void done() - { - imageFile.close(); - } - - public boolean hasValidCrcFile() - { - try { - return crcFile.isValid(); - } catch ( IOException e ) { - return false; - } - } - - /** - * Checks a chosen block against the crc file. - * - * @param block The block to check - * @return Whether the block was valid or not - * @throws IOException When image or crc file could not be read. - */ - public boolean checkBlock( int blockNumber ) throws IOException - { - if ( !this.hasValidCrcFile() ) - return false; - - int length; - try { - length = imageFile.getBlock( blockNumber, block ); - } catch ( IOException e ) { - throw new IOException( "Could not read image file", e ); - } - - if ( length <= 0 ) - return false; - - CRC32 crcCalc = new CRC32(); - if ( length == blockSize ) { - crcCalc.update( block ); - } else { - crcCalc.update( block, 0, length ); - } - - int crcSum = Integer.reverseBytes( (int)crcCalc.getValue() ); - int crcSumFromFile; - try { - crcSumFromFile = crcFile.getCRCSum( blockNumber ); - } catch ( IOException e ) { - throw new IOException( "Could not read CRC file", e ); - } - - return ( crcSum == crcSumFromFile ); - } -} |
