2 This file is to define nested element which is meant for specifying section file
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.framework
.tasks
;
16 import java
.io
.DataInputStream
;
17 import java
.io
.DataOutputStream
;
19 import java
.io
.FileInputStream
;
20 import org
.apache
.tools
.ant
.BuildException
;
23 Class SectFile is to define a class corresponding to ANT nested element. It's
24 used to specify section file(s) when used with GenFfsFile task
26 public class SectFile
implements Section
{
27 private String fileName
= ""; /// section file name
30 Get method of ANT task/datatype for "FileName" attribute
32 @returns The name of section file
34 public String
getFileName() {
39 Set method of ANT task/datatype for "FileName" attribute
41 @param fileName The name of section file
43 public void setFileName(String fileName
) {
44 this.fileName
= fileName
;
51 Put the content of section file into specified buffer with extra bytes for
52 alignment requirement.
54 @param Buffer buffer to contain the section file content with alignment
56 public void toBuffer (DataOutputStream buffer
){
63 sectFile
= new File (this.fileName
);
66 /// check if file exist.
68 if (! sectFile
.exists()) {
69 throw new BuildException("The file " + this.fileName
+ " is not exist!\n");
74 /// Read section file and add it's contains to buffer.
78 FileInputStream fs
= new FileInputStream (sectFile
.getAbsoluteFile());
79 DataInputStream In
= new DataInputStream (fs
);
80 fileLen
= (int)sectFile
.length();
81 byte[] sectBuffer
= new byte[fileLen
];
83 buffer
.write(sectBuffer
);
88 while ((fileLen
& 0x03)!= 0) {
98 } catch (Exception e
) {
99 System
.out
.print(e
.getMessage());
100 throw new BuildException("SectFile, toBuffer failed!\n");