]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
Support calling customized compression tool in FrameworkTask.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / CompressSection.java
index 674c6c86676ce13eeaee4a5d72260c423e3802fb..d0cc2f50dd3221db6135d665a2bf280d100f499a 100644 (file)
 \r
 package org.tianocore.framework.tasks;\r
 \r
-import java.io.DataInputStream;\r
+import java.io.ByteArrayOutputStream;\r
 import java.io.DataOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.List;\r
@@ -39,12 +36,13 @@ public class CompressSection implements Section, FfsTypes{
     //\r
     // The attribute of compressName.\r
     //\r
-    String compressName = "";\r
+    private String compressName = "";\r
     //\r
     // The list contained the SectFile element.\r
     //\r
-    List<Object>   SectList     = new ArrayList<Object>();\r
+    private List<Section> sectList = new ArrayList<Section>();\r
 \r
+    public static Object semaphore = new Object();\r
     /**\r
       toBuffer\r
       \r
@@ -54,24 +52,23 @@ public class CompressSection implements Section, FfsTypes{
       @param Buffer     The point of output buffer\r
       \r
     **/\r
-    public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){\r
+    public void toBuffer (DataOutputStream buffer){\r
         \r
         Section    sect;\r
-        File       compressOut;\r
     \r
         //\r
         //  Get section file in compress node.\r
         //\r
         try{\r
-            compressOut = new File ("Compress.temp");\r
-            FileOutputStream fo = new FileOutputStream (compressOut.getName());\r
-            DataOutputStream Do = new DataOutputStream (fo);\r
+            \r
+            ByteArrayOutputStream bo = new ByteArrayOutputStream ();\r
+            DataOutputStream Do = new DataOutputStream (bo);\r
             \r
             //\r
             //  Get each section which under the compress {};\r
             //  And add it is contains to File;\r
             //\r
-            Iterator SectionIter = SectList.iterator();\r
+            Iterator SectionIter = sectList.iterator();\r
             while (SectionIter.hasNext()){\r
                 sect = (Section)SectionIter.next();\r
                 \r
@@ -79,7 +76,7 @@ public class CompressSection implements Section, FfsTypes{
                 //  Call each section class's toBuffer function.\r
                 //\r
                 try {\r
-                    sect.toBuffer(Do, orgBuffer);\r
+                    sect.toBuffer(Do);\r
                 }\r
                 catch (BuildException e) {\r
                     System.out.print(e.getMessage());\r
@@ -89,17 +86,11 @@ public class CompressSection implements Section, FfsTypes{
             }\r
             Do.close();    \r
             \r
-            //\r
-            //  Get contain to Buffer\r
-            //\r
-            FileInputStream fi = new FileInputStream (compressOut.getName());\r
-            DataInputStream di = new DataInputStream (fi);\r
-            byte[] fileBuffer  = new byte[(int)compressOut.length()];\r
-            di.read(fileBuffer);\r
-            \r
+            synchronized (semaphore) {\r
             //\r
             //  Call compress\r
             //\r
+            byte[] fileBuffer = bo.toByteArray();\r
             Compress myCompress = new Compress(fileBuffer, fileBuffer.length);            \r
             \r
             //\r
@@ -151,18 +142,11 @@ public class CompressSection implements Section, FfsTypes{
                 buffer.writeByte(0);\r
             }\r
             //\r
-            // orgBuffer 4 Byte aligment\r
-            //\r
-            size = (int)compressOut.length();\r
-            while ((size & 0x03) != 0){\r
-                size ++;\r
-                orgBuffer.writeByte(0);\r
-            }\r
-            //\r
             //  Delete temp file\r
             //\r
-            di.close();\r
-            compressOut.delete();\r
+            //di.close();\r
+            //compressOut.delete();\r
+            }\r
                 \r
         }\r
         catch (Exception e){\r
@@ -200,7 +184,7 @@ public class CompressSection implements Section, FfsTypes{
       @param sectFile    SectFile element which succeed from section class.\r
     **/\r
     public void addSectFile (SectFile sectFile) {\r
-        SectList.add(sectFile);\r
+        sectList.add(sectFile);\r
             \r
     }    \r
     \r
@@ -211,6 +195,6 @@ public class CompressSection implements Section, FfsTypes{
       @param tool        Tool element which succeed from section class.\r
     **/\r
     public void addTool (Tool tool) {\r
-        SectList.add(tool);\r
+        sectList.add(tool);\r
     }\r
 }
\ No newline at end of file