summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/crcchecker
diff options
context:
space:
mode:
authorNils Schwabe2014-07-21 13:58:47 +0200
committerNils Schwabe2014-07-21 13:58:47 +0200
commitcd07d725aa694f77cd67ba56298735a2777ed227 (patch)
tree213331b1dce0785cc4af40e7c2bc80b07097b5c1 /src/main/java/org/openslx/imagemaster/crcchecker
parent[CRCFile] Add method to get the master sum (diff)
downloadmaster-sync-shared-cd07d725aa694f77cd67ba56298735a2777ed227.tar.gz
master-sync-shared-cd07d725aa694f77cd67ba56298735a2777ed227.tar.xz
master-sync-shared-cd07d725aa694f77cd67ba56298735a2777ed227.zip
[thrift] Add new error code for invalid blocks
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker')
-rw-r--r--src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
index be061ce..a096bf6 100644
--- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
+++ b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
@@ -11,14 +11,11 @@ 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;
@@ -57,7 +54,7 @@ public class CRCFile
DataOutputStream dos = new DataOutputStream( fos );
for ( Integer sum : listOfCrcSums ) {
- dos.writeInt( sum.intValue() ); // save byte-reversed integers to match right order in crc file TODO: is that right?
+ dos.writeInt( sum.intValue() );
}
dos.close();
@@ -74,13 +71,12 @@ public class CRCFile
{
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 );
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
+ int size = listOfCrcSums.size();
+ byte[] bytes = new byte[ size * Integer.SIZE / 8 ];
+ for ( int i = 0; i < size; i++ ) {
+ bytesOfInt = ByteBuffer.allocate( 4 ).putInt( listOfCrcSums.remove( 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];
@@ -88,8 +84,6 @@ public class CRCFile
}
CRC32 crcCalc = new CRC32();
crcCalc.update( bytes );
- log.debug( masterSum );
- log.debug( Integer.reverseBytes( (int)crcCalc.getValue() ) );
return ( masterSum == Integer.reverseBytes( (int)crcCalc.getValue() ) );
}