summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/crcchecker
diff options
context:
space:
mode:
authorNils Schwabe2014-07-16 15:37:34 +0200
committerNils Schwabe2014-07-16 15:37:34 +0200
commitc9f5b5ff1d27899aa296f8d2c7ed792ac6854e77 (patch)
treec27c5f7592750932d32720ea5bd68242c76ab4b5 /src/main/java/org/openslx/imagemaster/crcchecker
parentChange behaviour of CRCFile and CRCChecker (diff)
downloadmaster-sync-shared-c9f5b5ff1d27899aa296f8d2c7ed792ac6854e77.tar.gz
master-sync-shared-c9f5b5ff1d27899aa296f8d2c7ed792ac6854e77.tar.xz
master-sync-shared-c9f5b5ff1d27899aa296f8d2c7ed792ac6854e77.zip
[CRCFile] Add method to get the master sum
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker')
-rw-r--r--src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
index ade7bc0..be061ce 100644
--- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
+++ b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
@@ -6,15 +6,19 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.CRC32;
+import org.apache.log4j.Logger;
+
/**
* Represents a crc file
*/
public class CRCFile
{
+ private static Logger log = Logger.getLogger( CRCFile.class );
private File file = null;
private List<Integer> crcSums = null;
@@ -68,13 +72,24 @@ public class CRCFile
*/
public static boolean sumsAreValid( List<Integer> listOfCrcSums )
{
- byte[] bytes = new byte[ ( listOfCrcSums.size() - 1 ) * Integer.SIZE / 8 ];
+ if ( listOfCrcSums == null || listOfCrcSums.isEmpty() )
+ return false;
+
+ byte[] bytes = new byte[ ( listOfCrcSums.size() - 2 ) * Integer.SIZE / 8 ];
+ log.debug( listOfCrcSums.size() + ", " + bytes.length );
int masterSum = listOfCrcSums.remove( 0 );
- for ( int i = 0; i < bytes.length; i++ ) {
- bytes[i] = listOfCrcSums.remove( 0 ).byteValue();
+ byte[] bytesOfInt;
+ for ( int i = 0; i < ( listOfCrcSums.size() - 1 ); i++ ) {
+ bytesOfInt = ByteBuffer.allocate( 4 ).putInt( listOfCrcSums.get( 0 ) ).array(); // get the bytes of this integer
+ bytes[4 * i] = bytesOfInt[0];
+ bytes[4 * i + 1] = bytesOfInt[1];
+ bytes[4 * i + 2] = bytesOfInt[2];
+ bytes[4 * i + 3] = bytesOfInt[3];
}
CRC32 crcCalc = new CRC32();
crcCalc.update( bytes );
+ log.debug( masterSum );
+ log.debug( Integer.reverseBytes( (int)crcCalc.getValue() ) );
return ( masterSum == Integer.reverseBytes( (int)crcCalc.getValue() ) );
}
@@ -141,4 +156,11 @@ public class CRCFile
}
dis.close();
}
+
+ public int getMasterSum() throws IOException
+ {
+ if ( crcSums == null )
+ loadSums();
+ return this.crcSums.get( 0 );
+ }
}