Modify GenFfsTask to make it don't create ORG file.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / CompressSection.java
index 8def4ebc95908cfb4d9504415d2b514f500000ab..84f9176e786f7a120b9eae62eff8bb45a3fbe044 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
@@ -54,18 +51,17 @@ public class CompressSection implements Section, FfsTypes{
       @param Buffer     The point of output buffer\r
       \r
     **/\r
-    public void toBuffer (DataOutputStream Buffer){\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
@@ -89,17 +85,10 @@ 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
             //\r
             //  Call compress\r
             //\r
+            byte[] fileBuffer = bo.toByteArray();\r
             Compress myCompress = new Compress(fileBuffer, fileBuffer.length);            \r
             \r
             //\r
@@ -121,7 +110,7 @@ public class CompressSection implements Section, FfsTypes{
             Ch.SectionHeader.type    = (byte) EFI_SECTION_COMPRESSION;\r
             \r
             //\r
-            //  Note: The compressName was not effective now. Using the\r
+            //  Note: The compressName was not efsfective now. Using the\r
             //  EFI_STANDARD_COMPRSSION for compressType .\r
             //  That is follow old Genffsfile tools. Some code will be added for \r
             //  the different compressName;\r
@@ -138,24 +127,23 @@ public class CompressSection implements Section, FfsTypes{
             //\r
             //  First add CompressHeader to Buffer, then add Compress data.\r
             //\r
-            Buffer.write (headerBuffer);\r
-            Buffer.write(myCompress.outputBuffer);            \r
+            buffer.write (headerBuffer);\r
+            buffer.write(myCompress.outputBuffer);            \r
                 \r
             //\r
-            //  4 Byte aligment \r
+            //  Buffer 4 Byte aligment \r
             //\r
             int size = Ch.GetSize() + myCompress.outputBuffer.length;\r
             \r
             while ((size & 0x03) != 0){\r
                 size ++;\r
-                Buffer.writeByte(0);\r
+                buffer.writeByte(0);\r
             }\r
-            \r
             //\r
             //  Delete temp file\r
             //\r
-            di.close();\r
-            compressOut.delete();\r
+            //di.close();\r
+            //compressOut.delete();\r
                 \r
         }\r
         catch (Exception e){\r