summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/crcchecker
diff options
context:
space:
mode:
authorNils Schwabe2014-07-07 14:21:44 +0200
committerNils Schwabe2014-07-07 14:21:44 +0200
commited2475e55da3532831f979ff5877d867bc1b3781 (patch)
tree152dccccd07465aff71aa23efa3f2f9dd6507672 /src/main/java/org/openslx/imagemaster/crcchecker
parentBegin to implement crc scheduler (not working...) (diff)
downloadmaster-sync-shared-ed2475e55da3532831f979ff5877d867bc1b3781.tar.gz
master-sync-shared-ed2475e55da3532831f979ff5877d867bc1b3781.tar.xz
master-sync-shared-ed2475e55da3532831f979ff5877d867bc1b3781.zip
Add port to up- and download infos
Add function to CRCFile to create one from a list of crc sums
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker')
-rw-r--r--src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
index b557ada..74e3d84 100644
--- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
+++ b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
@@ -1,8 +1,11 @@
package org.openslx.imagemaster.crcchecker;
import java.io.DataInputStream;
+import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -18,8 +21,34 @@ public class CRCFile
private File file;
private List<Integer> crcSums = null;
- CRCFile(String filename) {
+ /**
+ * Loads a crcFile from file
+ * @param filename
+ */
+ CRCFile(String filename)
+ {
+ this.file = new File( filename );
+ }
+
+ /**
+ * Creates a new crc file with the given sums.
+ * The first crc sum in the list needs to be the sum over the other sums.
+ * @param listOfCrcSums The list of the crc sums that are going into the crc file
+ * @param filename Where to save the created crc file
+ * @throws IOException If it's not possible to write the file
+ */
+ CRCFile(List<Integer> listOfCrcSums, String filename) throws IOException
+ {
this.file = new File( filename );
+ FileOutputStream fos = new FileOutputStream( file );
+ DataOutputStream dos = new DataOutputStream( fos );
+
+ for ( Integer sum : listOfCrcSums ) {
+ dos.writeInt( Integer.reverseBytes( sum.intValue() ) ); // save byte-reversed integers to match right order in crc file
+ }
+
+ dos.close();
+ this.crcSums = listOfCrcSums;
}
/**