diff options
author | Michael Petretti | 2014-06-20 16:53:01 +0200 |
---|---|---|
committer | Michael Petretti | 2014-06-20 16:53:01 +0200 |
commit | 904d8c2f9c8d6bc8280bce8ba0338b0607bc3da8 (patch) | |
tree | 758a7c1e7c99dc541baa5cbd2dfcbdb599df7207 | |
parent | More debugging plus FtpDownloadWorker added. (diff) | |
download | satellite-daemon-904d8c2f9c8d6bc8280bce8ba0338b0607bc3da8.tar.gz satellite-daemon-904d8c2f9c8d6bc8280bce8ba0338b0607bc3da8.tar.xz satellite-daemon-904d8c2f9c8d6bc8280bce8ba0338b0607bc3da8.zip |
wrote a CRC32 Class. Not verified yet.
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java | 7 | ||||
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/util/CrcFile.java | 51 |
2 files changed, 54 insertions, 4 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java index 80e4d1a..13f3ae8 100644 --- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java @@ -66,10 +66,9 @@ public class FtpUploadWorker implements Runnable ftpClient.storeFile( image.name, fis ); ThriftConnection.finishedUpload( ftpc.username, imDat ); - } catch (IOException e) { - log.error("FtpUploadWorker: Error creating the FileInputStream"); - } - finally { + } catch ( IOException e ) { + log.error( "FtpUploadWorker: Error creating the FileInputStream" ); + } finally { ftpClient.disconnect(); log.info( "FtpUploadWorker: ftpClient disconnected" ); } diff --git a/src/main/java/org/openslx/satellitedaemon/util/CrcFile.java b/src/main/java/org/openslx/satellitedaemon/util/CrcFile.java new file mode 100644 index 0000000..ab8f190 --- /dev/null +++ b/src/main/java/org/openslx/satellitedaemon/util/CrcFile.java @@ -0,0 +1,51 @@ +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; + +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; + } +} |