]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
4 CompressSection indicate that all section which in it should be compressed.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.framework
.tasks
;
20 import java
.io
.DataInputStream
;
21 import java
.io
.DataOutputStream
;
23 import java
.io
.FileInputStream
;
24 import java
.io
.FileOutputStream
;
25 import java
.util
.ArrayList
;
26 import java
.util
.Iterator
;
27 import java
.util
.List
;
29 import org
.apache
.tools
.ant
.BuildException
;
35 CompressSection indicate that all section which in it should be compressed.
38 public class CompressSection
implements Section
, FfsTypes
{
40 // The attribute of compressName.
42 String compressName
= "";
44 // The list contained the SectFile element.
46 List
<Object
> SectList
= new ArrayList
<Object
>();
51 This function is to collect all sectFile and compress it , then output
54 @param Buffer The point of output buffer
57 public void toBuffer (DataOutputStream Buffer
){
63 // Get section file in compress node.
66 compressOut
= new File ("Compress.temp");
67 FileOutputStream fo
= new FileOutputStream (compressOut
.getName());
68 DataOutputStream Do
= new DataOutputStream (fo
);
71 // Get each section which under the compress {};
72 // And add it is contains to File;
74 Iterator SectionIter
= SectList
.iterator();
75 while (SectionIter
.hasNext()){
76 sect
= (Section
)SectionIter
.next();
79 // Call each section class's toBuffer function.
84 catch (BuildException e
) {
85 System
.out
.print(e
.getMessage());
86 throw new BuildException ("Compress.toBuffer failed at section");
93 // Get contain to Buffer
95 FileInputStream fi
= new FileInputStream (compressOut
.getName());
96 DataInputStream di
= new DataInputStream (fi
);
97 byte[] fileBuffer
= new byte[(int)compressOut
.length()];
103 Compress myCompress
= new Compress(fileBuffer
, fileBuffer
.length
);
106 // Add Compress header
108 CompressHeader Ch
= new CompressHeader();
109 Ch
.SectionHeader
.Size
[0] = (byte)((myCompress
.outputBuffer
.length
+
113 Ch
.SectionHeader
.Size
[1] = (byte)(((myCompress
.outputBuffer
.length
+
117 Ch
.SectionHeader
.Size
[2] = (byte)(((myCompress
.outputBuffer
.length
+
121 Ch
.SectionHeader
.type
= (byte) EFI_SECTION_COMPRESSION
;
124 // Note: The compressName was not effective now. Using the
125 // EFI_STANDARD_COMPRSSION for compressType .
126 // That is follow old Genffsfile tools. Some code will be added for
127 // the different compressName;
129 Ch
.UncompressLen
= fileBuffer
.length
;
130 Ch
.CompressType
= EFI_STANDARD_COMPRESSION
;
133 // Change header struct to byte buffer
135 byte [] headerBuffer
= new byte[Ch
.GetSize()];
136 Ch
.StructToBuffer(headerBuffer
);
139 // First add CompressHeader to Buffer, then add Compress data.
141 Buffer
.write (headerBuffer
);
142 Buffer
.write(myCompress
.outputBuffer
);
147 int size
= Ch
.GetSize() + myCompress
.outputBuffer
.length
;
149 while ((size
& 0x03) != 0){
158 compressOut
.delete();
162 throw new BuildException("compress.toBuffer failed!\n");
169 This function is to get compressName.
171 @return The compressName.
173 public String
getCompressName() {
180 This function is to set compressName.
182 @param compressName The string of compressName
184 public void setCompressName(String compressName
) {
185 this.compressName
= compressName
;
191 This function is to add sectFile element to SectList.
193 @param sectFile SectFile element which succeed from section class.
195 public void addSectFile (SectFile sectFile
) {
196 SectList
.add(sectFile
);
203 This function is to add tool element to SectList.
204 @param tool Tool element which succeed from section class.
206 public void addTool (Tool tool
) {