]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
Modify FV attribute editor and generate FvImage Attributes in FPD file.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / CompressSection.java
... / ...
CommitLineData
1/** @file\r
2 CompressSection class.\r
3\r
4 CompressSection indicate that all section which in it should be compressed.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16\r
17\r
18package org.tianocore.framework.tasks;\r
19\r
20import java.io.ByteArrayOutputStream;\r
21import java.io.DataOutputStream;\r
22import java.util.ArrayList;\r
23import java.util.Iterator;\r
24import java.util.List;\r
25\r
26import org.apache.tools.ant.BuildException;\r
27\r
28\r
29/**\r
30 CompressSection\r
31 \r
32 CompressSection indicate that all section which in it should be compressed. \r
33 \r
34**/\r
35public class CompressSection implements Section, FfsTypes{\r
36 //\r
37 // The attribute of compressName.\r
38 //\r
39 String compressName = "";\r
40 //\r
41 // The list contained the SectFile element.\r
42 //\r
43 List<Object> SectList = new ArrayList<Object>();\r
44\r
45 public static Object semaphore = new Object();\r
46 \r
47 /**\r
48 toBuffer\r
49 \r
50 This function is to collect all sectFile and compress it , then output\r
51 the result to buffer.\r
52 \r
53 @param Buffer The point of output buffer\r
54 \r
55 **/\r
56 public void toBuffer (DataOutputStream buffer){\r
57 \r
58 Section sect;\r
59 \r
60 //\r
61 // Get section file in compress node.\r
62 //\r
63 try{\r
64 \r
65 ByteArrayOutputStream bo = new ByteArrayOutputStream ();\r
66 DataOutputStream Do = new DataOutputStream (bo);\r
67 \r
68 //\r
69 // Get each section which under the compress {};\r
70 // And add it is contains to File;\r
71 //\r
72 Iterator SectionIter = SectList.iterator();\r
73 while (SectionIter.hasNext()){\r
74 sect = (Section)SectionIter.next();\r
75 \r
76 //\r
77 // Call each section class's toBuffer function.\r
78 //\r
79 try {\r
80 sect.toBuffer(Do);\r
81 }\r
82 catch (BuildException e) {\r
83 System.out.print(e.getMessage());\r
84 throw new BuildException ("Compress.toBuffer failed at section");\r
85 } \r
86 \r
87 }\r
88 Do.close(); \r
89 \r
90 \r
91 synchronized (semaphore) {\r
92 //\r
93 // Call compress\r
94 //\r
95 byte[] fileBuffer = bo.toByteArray();\r
96 Compress myCompress = new Compress(fileBuffer, fileBuffer.length); \r
97 \r
98 //\r
99 // Add Compress header\r
100 //\r
101 CompressHeader Ch = new CompressHeader();\r
102 Ch.SectionHeader.Size[0] = (byte)((myCompress.outputBuffer.length +\r
103 Ch.GetSize()) &\r
104 0xff\r
105 );\r
106 Ch.SectionHeader.Size[1] = (byte)(((myCompress.outputBuffer.length + \r
107 Ch.GetSize())&\r
108 0xff00) >> 8\r
109 );\r
110 Ch.SectionHeader.Size[2] = (byte)(((myCompress.outputBuffer.length + \r
111 Ch.GetSize()) & \r
112 0xff0000) >> 16\r
113 );\r
114 Ch.SectionHeader.type = (byte) EFI_SECTION_COMPRESSION;\r
115 \r
116 //\r
117 // Note: The compressName was not efsfective now. Using the\r
118 // EFI_STANDARD_COMPRSSION for compressType .\r
119 // That is follow old Genffsfile tools. Some code will be added for \r
120 // the different compressName;\r
121 //\r
122 Ch.UncompressLen = fileBuffer.length;\r
123 Ch.CompressType = EFI_STANDARD_COMPRESSION; \r
124 \r
125 //\r
126 // Change header struct to byte buffer\r
127 //\r
128 byte [] headerBuffer = new byte[Ch.GetSize()];\r
129 Ch.StructToBuffer(headerBuffer);\r
130 \r
131 //\r
132 // First add CompressHeader to Buffer, then add Compress data.\r
133 //\r
134 buffer.write (headerBuffer);\r
135 buffer.write(myCompress.outputBuffer); \r
136 \r
137 //\r
138 // Buffer 4 Byte aligment \r
139 //\r
140 int size = Ch.GetSize() + myCompress.outputBuffer.length;\r
141 \r
142 while ((size & 0x03) != 0){\r
143 size ++;\r
144 buffer.writeByte(0);\r
145 }\r
146 //\r
147 // Delete temp file\r
148 //\r
149 //di.close();\r
150 //compressOut.delete();\r
151 }\r
152 \r
153 }\r
154 catch (Exception e){\r
155 throw new BuildException("compress.toBuffer failed!\n");\r
156 } \r
157 }\r
158\r
159 /**\r
160 getCompressName\r
161 \r
162 This function is to get compressName.\r
163 \r
164 @return The compressName.\r
165 **/\r
166 public String getCompressName() {\r
167 return compressName;\r
168 }\r
169\r
170 /**\r
171 setCompressName\r
172 \r
173 This function is to set compressName.\r
174 \r
175 @param compressName The string of compressName\r
176 **/\r
177 public void setCompressName(String compressName) {\r
178 this.compressName = compressName;\r
179 }\r
180\r
181 /**\r
182 addSectFile\r
183 \r
184 This function is to add sectFile element to SectList.\r
185 \r
186 @param sectFile SectFile element which succeed from section class.\r
187 **/\r
188 public void addSectFile (SectFile sectFile) {\r
189 SectList.add(sectFile);\r
190 \r
191 } \r
192 \r
193 /**\r
194 addTool\r
195 \r
196 This function is to add tool element to SectList.\r
197 @param tool Tool element which succeed from section class.\r
198 **/\r
199 public void addTool (Tool tool) {\r
200 SectList.add(tool);\r
201 }\r
202}