Bitsplitter plugin now works.
authorMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Thu, 31 Jul 2014 08:43:46 +0000 (10:43 +0200)
committerMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Thu, 31 Jul 2014 08:43:46 +0000 (10:43 +0200)
Splitter-ng-plugin-bitsplitter/src/bitsplitterplugin/BitsplitterPlugin.java
Splitter-ng-plugin-bitsplitter/src/bitsplitterplugin/CodecBitsplitter.java
Splitter-ng-test/src/SplitterTest.java

index 9148eb7..c831611 100644 (file)
@@ -49,26 +49,26 @@ public class BitsplitterPlugin implements Plugable {
                        System.err
                                        .println("Native code library failed to load \n"
                                                        + e);
-                       Field loadedLibraryNamesField = null;
-                       try {
-                               loadedLibraryNamesField = ClassLoader.class
-                                  .getDeclaredField("loadedLibraryNames");
-                       } catch (NoSuchFieldException | SecurityException e1) {
-                               // TODO Auto-generated catch block
-                               e1.printStackTrace();
-                       }
-                   loadedLibraryNamesField.setAccessible(true);
-                   @SuppressWarnings("unchecked")
-                       Vector<String> loadedLibraryNames = null;
-                       try {
-                               loadedLibraryNames = (Vector<String>) loadedLibraryNamesField.get(null);
-                       } catch (IllegalArgumentException | IllegalAccessException en) {
-                               // TODO Auto-generated catch block
-                               en.printStackTrace();
-                       }
-                   for (String string : loadedLibraryNames) {
-                       System.out.println(string);
-                   }
+//                     Field loadedLibraryNamesField = null;
+//                     try {
+//                             loadedLibraryNamesField = ClassLoader.class
+//                                .getDeclaredField("loadedLibraryNames");
+//                     } catch (NoSuchFieldException | SecurityException e1) {
+//                             // TODO Auto-generated catch block
+//                             e1.printStackTrace();
+//                     }
+//                 loadedLibraryNamesField.setAccessible(true);
+//                 @SuppressWarnings("unchecked")
+//                     Vector<String> loadedLibraryNames = null;
+//                     try {
+//                             loadedLibraryNames = (Vector<String>) loadedLibraryNamesField.get(null);
+//                     } catch (IllegalArgumentException | IllegalAccessException en) {
+//                             // TODO Auto-generated catch block
+//                             en.printStackTrace();
+//                     }
+//                 for (String string : loadedLibraryNames) {
+//                     System.out.println(string);
+//                 }
                }
 
                // codecMap.put(JerasureCodecParity.getCodecDescription().getCodecID(),
index 4004579..a94cb3b 100644 (file)
@@ -2,21 +2,25 @@ package bitsplitterplugin;
 
 
 
-import java.util.ArrayList;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import BitSplitter.BitSplitter;
 import splitterng.plugin.CodecDescription;
 import splitterng.plugin.interfaces.SplitterCodec;
+import BitSplitter.BitSplitter;
 
 
 public class CodecBitsplitter implements SplitterCodec {
 
-       public final static String codecID = "Bitsplitter";
+       public final static String codecID = "bitsplitter";
        public final static String codecName = "Bitsplitter";
        public final static String codecDescriptionText = "Simple bitsplitter. 1234567812345678 -> 12341234 56785678";
 
@@ -26,8 +30,8 @@ public class CodecBitsplitter implements SplitterCodec {
        
        static {
                Map <String, Integer []> tmpMap = new HashMap<String, Integer[]>();
-               tmpMap.put("k", new Integer[] {new Integer(1),new Integer(Integer.MAX_VALUE)});
-               tmpMap.put("m", new Integer[] {new Integer(0),new Integer(1)});
+               tmpMap.put("k", new Integer[] {new Integer(2),new Integer(Integer.MAX_VALUE)});
+               tmpMap.put("m", new Integer[] {new Integer(0),new Integer(0)});
                
                codecParameterMinMax  = Collections.unmodifiableMap(tmpMap);                            
        }
@@ -41,6 +45,7 @@ public class CodecBitsplitter implements SplitterCodec {
        private byte[][] dataAndCoding_ptrs;
        BitSplitter bs;
        private int [] erasures;
+       private byte[] data_ptrs_flat;
        
        
        public static final CodecDescription getCodecDescription(){
@@ -53,7 +58,6 @@ public class CodecBitsplitter implements SplitterCodec {
         */
        public CodecBitsplitter(Map<String, Integer> codecParameter) {
                super();
-               
                //Test CodecParameter
                for (Entry<String, Integer[]> requiredEntry : CodecBitsplitter.codecParameterMinMax
                                .entrySet()) {
@@ -79,27 +83,28 @@ public class CodecBitsplitter implements SplitterCodec {
                
                k=(int)codecParameter.get("k");
                m=(int)codecParameter.get("m");
+               System.out.println("Init Bitsplitter");
                bs = new BitSplitter();
-               
        }
 
        @Override
        public byte[][] decode(byte[][] dataAndCoding_ptrs, boolean [] erased){
                //TODO Array Testen ob zulässig? eventuell nicht, da es hier bremsen könnte
-               int fragmentsize = dataAndCoding_ptrs[0].length;
                
-               checkArraySizes(fragmentsize);
+               int fragmentsize = dataAndCoding_ptrs[0].length;
                
-               for (int i=0; i<k ; i++){
-                       data_ptrs[i]=dataAndCoding_ptrs[i];
-               }
-               for (int i=k; i<k+m ; i++){
-                       coding_ptrs[i-k]=dataAndCoding_ptrs[i];
+               if (data_ptrs_flat == null || (data_ptrs_flat.length != k * fragmentsize)){
+                       data_ptrs_flat = new byte[k * fragmentsize];
                }
+               if (data_ptrs == null || (data_ptrs.length != k) || (data_ptrs[0].length != fragmentsize)){
+                       data_ptrs = new byte[k][fragmentsize];
+               }                       
                
-               throw new IllegalArgumentException("Decoding not jet implemented... sorry");
-               //bs.bitjoinfile(null, null, (Integer) null);
+               bs.bitjoinbuffer(dataAndCoding_ptrs, data_ptrs_flat, k);
 
+               for (int i=0; i<k; i++){
+                       System.arraycopy(data_ptrs_flat, i*fragmentsize, data_ptrs[i], 0, fragmentsize);
+               }
                return data_ptrs;
        }
 
@@ -109,20 +114,19 @@ public class CodecBitsplitter implements SplitterCodec {
                // buffersize%(sizeof(int)*w*k) == 0
                int fragmentsize = data_ptrs[0].length;
                
-               checkArraySizes(fragmentsize);
-
-               /*TODO
-                * Daten array flach machen
-                * Temp Verzeichnis erstellen
-                * In eine Temp Datei schreiben
-                * splitten in tempverzeichnis
-                * splitstreams einlesen
-                * Array packen
-                * zurückgeben
-                */
-               //Path tempDir = Files.createTempDirectory("bitsplittemp");
-               bs.bitsplitfile(null, null, k, m);
-               
+               if (data_ptrs_flat == null || (data_ptrs_flat.length != k * fragmentsize)){
+                       data_ptrs_flat = new byte[k * fragmentsize];
+               }
+               for (int i=0; i < k; i++) {
+                       System.arraycopy(data_ptrs[i], 0, data_ptrs_flat, i*fragmentsize , fragmentsize);
+               }               
+               if (dataAndCoding_ptrs == null || (dataAndCoding_ptrs.length != k+m) || (dataAndCoding_ptrs[0].length != Math.ceil(fragmentsize/k))){
+                       System.out.println("dataAndCoding_ptrs neu");
+                       dataAndCoding_ptrs = new byte[k+m][(int) Math.ceil(fragmentsize/k)];
+               }else {
+                       System.out.println("dataAndCoding_ptrs reuse");
+               }
+               bs.bitsplitbuffer(data_ptrs_flat, dataAndCoding_ptrs, k, m);
                                
                return dataAndCoding_ptrs;
        }
@@ -142,12 +146,15 @@ public class CodecBitsplitter implements SplitterCodec {
 //                     coding_ptrs_flat = new byte[m * fragmentsize];
 //             }
                
-               if (coding_ptrs == null || (coding_ptrs.length != m ) || (coding_ptrs[0].length != fragmentsize)){
-                       coding_ptrs = new byte[m][fragmentsize];
-               }
+//             if (coding_ptrs == null || (coding_ptrs.length != m ) || (coding_ptrs[0].length != fragmentsize)){
+//                     coding_ptrs = new byte[m][fragmentsize];
+//             }
                
-               if (dataAndCoding_ptrs == null || (dataAndCoding_ptrs.length != k+m) || (dataAndCoding_ptrs[0].length != fragmentsize)){
-                       dataAndCoding_ptrs = new byte[k+m][fragmentsize];
+               if (dataAndCoding_ptrs == null || (dataAndCoding_ptrs.length != k+m) || (dataAndCoding_ptrs[0].length != fragmentsize/k +1)){
+                       System.out.println("dataAndCoding_ptrs neu");
+                       dataAndCoding_ptrs = new byte[k+m][fragmentsize/k +1];
+               }else {
+                       System.out.println("dataAndCoding_ptrs reuse");
                }
        }
        private void fill(int fragmentsize) {
index 98ad6ce..13bc25b 100644 (file)
@@ -239,7 +239,28 @@ public class SplitterTest implements SplitterCallback {
                                        splitter_metadata_map.put(splitterjerasure111, metadatajerasure111);
                                        break;
 ///-----------------------------------------------------------------------------------------------
-
+                                       
+                               case "bitsplitter/bitsplitter":
+                                       // Codecparameter Bauen
+                                       Map<String, Integer> codecParameter1111 = new TreeMap<String, Integer>();
+                                       codecParameter1111.put("k", 2);
+                                       codecParameter1111.put("m", 0);
+                                       System.out.println("\t\tinitialisiere mit" + " k="
+                                                       + codecParameter1111.get("k") + " m="
+                                                       + codecParameter1111.get("m") + " w=" );
+                                       // Splitter mit Plugin-ID CodecID und codecparametern
+                                       // initialisieren
+                                       Splitter splitter1111 = new Splitter(p.getPluginID(), c.getCodecID(),
+                                                       codecParameter1111);
+                                       splitters.add(splitter1111);
+                                       
+                                       // Metadaten bauen vorlage
+                                       Map<String, Object> metadata1111 = new TreeMap<String, Object>();
+                                       metadata1111.put("fragmentsize", (int) 256);
+                                       // Beleiebige weitere Metadaten
+                                       
+                                       splitter_metadata_map.put(splitter1111, metadata1111);
+                                       break;
 ///-----------------------------------------------------------------------------------------------
 ///-----------------------------------------------------------------------------------------------
 ///-----------------------------------------------------------------------------------------------