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
28 private int alignment
= 0;
31 Get method of ANT task/datatype for "FileName" attribute
33 @returns The name of section file
35 public String
getFileName() {
40 Set method of ANT task/datatype for "FileName" attribute
42 @param fileName The name of section file
44 public void setFileName(String fileName
) {
45 this.fileName
= fileName
;
48 public int getAlignment() {
52 public void setAlignment(int alignment
) {
56 this.alignment
= alignment
;
64 Put the content of section file into specified buffer with extra bytes for
65 alignment requirement.
67 @param Buffer buffer to contain the section file content with alignment
69 public void toBuffer (DataOutputStream buffer
){
76 sectFile
= new File (this.fileName
);
79 /// check if file exist.
81 if (! sectFile
.exists()) {
82 throw new BuildException("The file " + this.fileName
+ " is not exist!\n");
87 /// Read section file and add it's contains to buffer.
91 FileInputStream fs
= new FileInputStream (sectFile
.getAbsoluteFile());
92 DataInputStream In
= new DataInputStream (fs
);
93 fileLen
= (int)sectFile
.length();
94 byte[] sectBuffer
= new byte[fileLen
];
96 buffer
.write(sectBuffer
);
101 while ((fileLen
& 0x03)!= 0) {
107 /// close inputStream
111 } catch (Exception e
) {
112 System
.out
.print(e
.getMessage());
113 throw new BuildException("SectFile, toBuffer failed!\n");