summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
diff options
context:
space:
mode:
authorlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>2006-10-05 23:12:07 +0000
committerlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>2006-10-05 23:12:07 +0000
commitfeccee87a78e68d575dbdf44b34ca0cb5a21ea8d (patch)
treec70bdaea30cf92a8555e1013fc15565138203134 /Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
parent214b0d1914b48d651b25e58f321ddb77a46903b8 (diff)
downloadedk2-platforms-feccee87a78e68d575dbdf44b34ca0cb5a21ea8d.tar.xz
Restructuring for better separation of Tool packages.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1674 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java')
-rw-r--r--Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java200
1 files changed, 200 insertions, 0 deletions
diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
new file mode 100644
index 0000000000..5f35685fbe
--- /dev/null
+++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
@@ -0,0 +1,200 @@
+/** @file
+ CompressSection class.
+
+ CompressSection indicate that all section which in it should be compressed.
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ **/
+
+
+package org.tianocore.framework.tasks;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+
+
+/**
+ CompressSection
+
+ CompressSection indicate that all section which in it should be compressed.
+
+**/
+public class CompressSection implements Section, FfsTypes {
+ //
+ // The attribute of compressName.
+ //
+ private String compressName = "";
+ //
+ // The list contained the SectFile element.
+ //
+ private List<Section> sectList = new ArrayList<Section>();
+
+ public static Object semaphore = new Object();
+ /**
+ toBuffer
+
+ This function is to collect all sectFile and compress it , then output
+ the result to buffer.
+
+ @param Buffer The point of output buffer
+
+ **/
+ public void toBuffer (DataOutputStream buffer){
+
+ Section sect;
+
+ //
+ // Get section file in compress node.
+ //
+ try{
+
+ ByteArrayOutputStream bo = new ByteArrayOutputStream ();
+ DataOutputStream Do = new DataOutputStream (bo);
+
+ //
+ // Get each section which under the compress {};
+ // And add it is contains to File;
+ //
+ Iterator SectionIter = sectList.iterator();
+ while (SectionIter.hasNext()){
+ sect = (Section)SectionIter.next();
+
+ //
+ // Call each section class's toBuffer function.
+ //
+ try {
+ sect.toBuffer(Do);
+ }
+ catch (BuildException e) {
+ System.out.print(e.getMessage());
+ throw new BuildException ("Compress.toBuffer failed at section");
+ }
+
+ }
+ Do.close();
+
+ synchronized (semaphore) {
+ //
+ // Call compress
+ //
+ byte[] fileBuffer = bo.toByteArray();
+ Compress myCompress = new Compress(fileBuffer, fileBuffer.length);
+
+ //
+ // Add Compress header
+ //
+ CompressHeader Ch = new CompressHeader();
+ Ch.SectionHeader.Size[0] = (byte)((myCompress.outputBuffer.length +
+ Ch.GetSize()) &
+ 0xff
+ );
+ Ch.SectionHeader.Size[1] = (byte)(((myCompress.outputBuffer.length +
+ Ch.GetSize())&
+ 0xff00) >> 8
+ );
+ Ch.SectionHeader.Size[2] = (byte)(((myCompress.outputBuffer.length +
+ Ch.GetSize()) &
+ 0xff0000) >> 16
+ );
+ Ch.SectionHeader.type = (byte) EFI_SECTION_COMPRESSION;
+
+ //
+ // Note: The compressName was not efsfective now. Using the
+ // EFI_STANDARD_COMPRSSION for compressType .
+ // That is follow old Genffsfile tools. Some code will be added for
+ // the different compressName;
+ //
+ Ch.UncompressLen = fileBuffer.length;
+ Ch.CompressType = EFI_STANDARD_COMPRESSION;
+
+ //
+ // Change header struct to byte buffer
+ //
+ byte [] headerBuffer = new byte[Ch.GetSize()];
+ Ch.StructToBuffer(headerBuffer);
+
+ //
+ // First add CompressHeader to Buffer, then add Compress data.
+ //
+ buffer.write (headerBuffer);
+ buffer.write(myCompress.outputBuffer);
+
+ //
+ // Buffer 4 Byte aligment
+ //
+ int size = Ch.GetSize() + myCompress.outputBuffer.length;
+
+ while ((size & 0x03) != 0){
+ size ++;
+ buffer.writeByte(0);
+ }
+ //
+ // Delete temp file
+ //
+ //di.close();
+ //compressOut.delete();
+ }
+
+ }
+ catch (Exception e){
+ throw new BuildException("compress.toBuffer failed!\n");
+ }
+ }
+
+ /**
+ getCompressName
+
+ This function is to get compressName.
+
+ @return The compressName.
+ **/
+ public String getCompressName() {
+ return compressName;
+ }
+
+ /**
+ setCompressName
+
+ This function is to set compressName.
+
+ @param compressName The string of compressName
+ **/
+ public void setCompressName(String compressName) {
+ this.compressName = compressName;
+ }
+
+ /**
+ addSectFile
+
+ This function is to add sectFile element to SectList.
+
+ @param sectFile SectFile element which succeed from section class.
+ **/
+ public void addSectFile (SectFile sectFile) {
+ sectList.add(sectFile);
+
+ }
+
+ /**
+ addTool
+
+ This function is to add tool element to SectList.
+ @param tool Tool element which succeed from section class.
+ **/
+ public void addTool (Tool tool) {
+ sectList.add(tool);
+ }
+} \ No newline at end of file