Bitsplitter-Plugin: add methods to recover reased fragment in the codec
authorMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Mon, 3 Nov 2014 13:57:11 +0000 (14:57 +0100)
committerMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Mon, 3 Nov 2014 13:57:11 +0000 (14:57 +0100)
Splitter-ng-plugin-bitsplitter/src/bitsplitterplugin/CodecBitsplitter.java

index 39d5490..3f5e47f 100644 (file)
@@ -8,6 +8,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -31,7 +32,7 @@ public class CodecBitsplitter implements SplitterCodec {
        static {
                Map <String, Integer []> tmpMap = new HashMap<String, Integer[]>();
                tmpMap.put("k", new Integer[] {new Integer(2),new Integer(Integer.MAX_VALUE)});
-               tmpMap.put("m", new Integer[] {new Integer(0),new Integer(0)});
+               tmpMap.put("m", new Integer[] {new Integer(0),new Integer(1)});
                
                codecParameterMinMax  = Collections.unmodifiableMap(tmpMap);                            
        }
@@ -92,6 +93,15 @@ public class CodecBitsplitter implements SplitterCodec {
                //TODO Array Testen ob zulässig? eventuell nicht, da es hier bremsen könnte
                
                int fragmentsize = dataAndCoding_ptrs[0].length;
+               int erased_index=0;
+               for (boolean e: erased){
+                       if (e){
+                               recoverFragment(dataAndCoding_ptrs,erased_index);
+                               break;
+                       } else {
+                               erased_index++;
+                       }
+               }
                
                if (data_ptrs_flat == null || (data_ptrs_flat.length != k * fragmentsize)){
                        data_ptrs_flat = new byte[k * fragmentsize];
@@ -108,6 +118,21 @@ public class CodecBitsplitter implements SplitterCodec {
                return data_ptrs;
        }
 
+       private void recoverFragment(byte[][] dataAndCoding_ptrs2, int erased_index) {
+               // TODO Auto-generated method stub
+               int parts= dataAndCoding_ptrs2.length;
+               Arrays.fill(dataAndCoding_ptrs2[erased_index],(byte)0);
+               int i = 0;
+               for (byte [] array : dataAndCoding_ptrs2){
+                       if (i != erased_index){
+                               int j = 0;
+                               for (byte b : array)
+                                       dataAndCoding_ptrs2[erased_index][j] = (byte) (b ^ dataAndCoding_ptrs2[erased_index][j++]);
+                       }
+                       i++;
+               }
+       }
+
        @Override
        public byte[][] encode(byte[][] data_ptrs){
                //TODO Array Testen ob zulässig? eventuell nicht, da es hier bremsen könnte
@@ -157,8 +182,4 @@ public class CodecBitsplitter implements SplitterCodec {
                        //System.out.println("dataAndCoding_ptrs reuse");
                }
        }
-       private void fill(int fragmentsize) {
-       
-       }
-       
 }
\ No newline at end of file