]>
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
.ByteArrayOutputStream
;
21 import java
.io
.DataOutputStream
;
22 import java
.util
.ArrayList
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
26 import org
.apache
.tools
.ant
.BuildException
;
32 CompressSection indicate that all section which in it should be compressed.
35 public class CompressSection
implements Section
, FfsTypes
{
37 // The attribute of compressName.
39 String compressName
= "";
41 // The list contained the SectFile element.
43 List
<Object
> SectList
= new ArrayList
<Object
>();
45 public static Object semaphore
= new Object();
50 This function is to collect all sectFile and compress it , then output
53 @param Buffer The point of output buffer
56 public void toBuffer (DataOutputStream buffer
){
61 // Get section file in compress node.
65 ByteArrayOutputStream bo
= new ByteArrayOutputStream ();
66 DataOutputStream Do
= new DataOutputStream (bo
);
69 // Get each section which under the compress {};
70 // And add it is contains to File;
72 Iterator SectionIter
= SectList
.iterator();
73 while (SectionIter
.hasNext()){
74 sect
= (Section
)SectionIter
.next();
77 // Call each section class's toBuffer function.
82 catch (BuildException e
) {
83 System
.out
.print(e
.getMessage());
84 throw new BuildException ("Compress.toBuffer failed at section");
91 synchronized (semaphore
) {
95 byte[] fileBuffer
= bo
.toByteArray();
96 Compress myCompress
= new Compress(fileBuffer
, fileBuffer
.length
);
99 // Add Compress header
101 CompressHeader Ch
= new CompressHeader();
102 Ch
.SectionHeader
.Size
[0] = (byte)((myCompress
.outputBuffer
.length
+
106 Ch
.SectionHeader
.Size
[1] = (byte)(((myCompress
.outputBuffer
.length
+
110 Ch
.SectionHeader
.Size
[2] = (byte)(((myCompress
.outputBuffer
.length
+
114 Ch
.SectionHeader
.type
= (byte) EFI_SECTION_COMPRESSION
;
117 // Note: The compressName was not efsfective now. Using the
118 // EFI_STANDARD_COMPRSSION for compressType .
119 // That is follow old Genffsfile tools. Some code will be added for
120 // the different compressName;
122 Ch
.UncompressLen
= fileBuffer
.length
;
123 Ch
.CompressType
= EFI_STANDARD_COMPRESSION
;
126 // Change header struct to byte buffer
128 byte [] headerBuffer
= new byte[Ch
.GetSize()];
129 Ch
.StructToBuffer(headerBuffer
);
132 // First add CompressHeader to Buffer, then add Compress data.
134 buffer
.write (headerBuffer
);
135 buffer
.write(myCompress
.outputBuffer
);
138 // Buffer 4 Byte aligment
140 int size
= Ch
.GetSize() + myCompress
.outputBuffer
.length
;
142 while ((size
& 0x03) != 0){
150 //compressOut.delete();
155 throw new BuildException("compress.toBuffer failed!\n");
162 This function is to get compressName.
164 @return The compressName.
166 public String
getCompressName() {
173 This function is to set compressName.
175 @param compressName The string of compressName
177 public void setCompressName(String compressName
) {
178 this.compressName
= compressName
;
184 This function is to add sectFile element to SectList.
186 @param sectFile SectFile element which succeed from section class.
188 public void addSectFile (SectFile sectFile
) {
189 SectList
.add(sectFile
);
196 This function is to add tool element to SectList.
197 @param tool Tool element which succeed from section class.
199 public void addTool (Tool tool
) {