summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java24
-rw-r--r--src/main/java/org/openslx/satellitedaemon/util/CrcFile.java53
2 files changed, 12 insertions, 65 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
index efd5357..2f0ef46 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -17,7 +17,7 @@ import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
-import org.openslx.imagemaster.crcchecker.CRCFile;
+import org.openslx.imagemaster.crcchecker.CrcFile;
import org.openslx.imagemaster.thrift.iface.AuthorizationError;
import org.openslx.imagemaster.thrift.iface.AuthorizationException;
import org.openslx.imagemaster.thrift.iface.DownloadInfos;
@@ -48,7 +48,7 @@ public class ThriftConnection
private static ImageServer.Client client = null;
private static ServerSessionData sSD = null;
private static Logger log = Logger.getLogger( ThriftConnection.class );
- private static CRCFile crc = null;
+ private static CrcFile crc = null;
/***********************************************************************************************/
/**
@@ -75,13 +75,13 @@ public class ThriftConnection
// .submitImage needs the List<Integer> from CRCFile.getCRCs() only
// on the first time called. null afterwards.
log.info( "First call of submitImage following..." );
- crc = new CRCFile( filename );
+ crc = new CrcFile( filename );
log.info( "Made CRCFile from " + filename );
log.info( "crc.getCrcSums( ).size = " + crc.getCrcSums().size() );
-// log.info( "crc.getMasterSum() : " + crc.getMasterSum() );
-// for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) {
-// log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) );
-// }
+ // log.info( "crc.getMasterSum() : " + crc.getMasterSum() );
+ // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) {
+ // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) );
+ // }
return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() );
} catch ( ImageDataException e ) {
if ( e.isSetNumber() && e.getNumber().equals( ImageDataError.INVALID_DATA ) ) {
@@ -96,9 +96,9 @@ public class ThriftConnection
// TODO: Mark the Image as corrupted.
} else if ( e.getNumber().equals( UploadError.INVALID_CRC ) ) {
// The CRC sum contained errors
- crc = new CRCFile( filename );
+ crc = new CrcFile( filename );
try {
- if(!crc.isValid()){
+ if ( !crc.isValid() ) {
//TODO: Mark CRC-file as corrupted.
}
} catch ( IOException e1 ) {
@@ -173,7 +173,7 @@ public class ThriftConnection
if ( e.isSetNumber() && e.getNumber().equals( ImageDataError.INVALID_DATA ) ) {
// Data in the db is not valid
//TODO: add e.message into DB;
- } else {
+ } else {
e.printStackTrace();
}
} catch ( UploadException e ) {
@@ -183,7 +183,7 @@ public class ThriftConnection
} else if ( e.getNumber().equals( UploadError.INVALID_CRC ) ) {
// The CRC sum contained errors
try {
- if(!crc.isValid()){
+ if ( !crc.isValid() ) {
//TODO: Mark CRC-file as corrupted.
}
} catch ( IOException e1 ) {
@@ -261,7 +261,7 @@ public class ThriftConnection
} else {
e.printStackTrace();
}
- } catch ( AuthorizationException e ) {
+ } catch ( AuthorizationException e ) {
if ( e.isSetNumber() && e.getNumber().equals( AuthorizationError.NOT_AUTHENTICATED ) ) {
// SessionID is not valid
// TODO: Code for new SSID
diff --git a/src/main/java/org/openslx/satellitedaemon/util/CrcFile.java b/src/main/java/org/openslx/satellitedaemon/util/CrcFile.java
deleted file mode 100644
index 59679d3..0000000
--- a/src/main/java/org/openslx/satellitedaemon/util/CrcFile.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.openslx.satellitedaemon.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.zip.CRC32;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Logger;
-
-// TODO: Merge with code/classes from masterser and put into master-sync-shared
-
-public class CrcFile
-{
- private static Logger log = Logger.getLogger( CrcFile.class );
- public static void make( String path ) throws IOException
- {
- int blockSize = 16 * 1024 * 1024;
- InputStream is = new FileInputStream( path );
- CRC32 crc = new CRC32();
- int cnt;
- byte[] block = new byte[blockSize];
- byte[] WriteToFile = new byte[0];
- log.info( "Inputfile: " + path );
- while ( ( cnt = is.read(block) ) != -1 ) {
- crc.update( cnt );
- log.info( "CRC value: " + crc.getValue() );
- byte[] latest = ByteBuffer.allocate(8).putLong(crc.getValue()).array();
- WriteToFile = concatenateByteArrays( WriteToFile, latest );
- }
- String outPath = path.substring( 0, (path.length() - 4) ).concat( "crc" );
- File outFile = new File(outPath);
- FileOutputStream fos = new FileOutputStream( outFile );
- fos.write( WriteToFile );
- is.close();
- fos.close();
- }
-
- public static void main( String[] args ) throws IOException {
- BasicConfigurator.configure();
- CrcFile.make( "/tmp/test.vmdk");
- }
-
- public static byte[] concatenateByteArrays(byte[] a, byte[] b) {
- byte[] result = new byte[a.length + b.length];
- System.arraycopy(a, 0, result, 0, a.length);
- System.arraycopy(b, 0, result, a.length, b.length);
- return result;
- }
-}