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
, DataOutputStream orgBuffer
){
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.
82 sect
.toBuffer(Do
, orgBuffer
);
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 efsfective 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
);
145 // Buffer 4 Byte aligment
147 int size
= Ch
.GetSize() + myCompress
.outputBuffer
.length
;
149 while ((size
& 0x03) != 0){
154 // orgBuffer 4 Byte aligment
156 size
= (int)compressOut
.length();
157 while ((size
& 0x03) != 0){
159 orgBuffer
.writeByte(0);
165 compressOut
.delete();
169 throw new BuildException("compress.toBuffer failed!\n");
176 This function is to get compressName.
178 @return The compressName.
180 public String
getCompressName() {
187 This function is to set compressName.
189 @param compressName The string of compressName
191 public void setCompressName(String compressName
) {
192 this.compressName
= compressName
;
198 This function is to add sectFile element to SectList.
200 @param sectFile SectFile element which succeed from section class.
202 public void addSectFile (SectFile sectFile
) {
203 SectList
.add(sectFile
);
210 This function is to add tool element to SectList.
211 @param tool Tool element which succeed from section class.
213 public void addTool (Tool tool
) {