+++ /dev/null
-/** @file\r
-This file is to define nested element which is meant for specifying section file\r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-package org.tianocore.framework.tasks;\r
-\r
-import java.io.DataInputStream;\r
-import java.io.DataOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import org.apache.tools.ant.BuildException;\r
-\r
-/**\r
- Class SectFile is to define a class corresponding to ANT nested element. It's\r
- used to specify section file(s) when used with GenFfsFile task\r
- **/\r
-public class SectFile implements Section {\r
- private String fileName = ""; /// section file name\r
- private int alignment = 0;\r
-\r
- /**\r
- Get method of ANT task/datatype for "FileName" attribute\r
- \r
- @returns The name of section file\r
- **/\r
- public String getFileName() {\r
- return fileName;\r
- }\r
-\r
- /**\r
- Set method of ANT task/datatype for "FileName" attribute\r
- \r
- @param fileName The name of section file\r
- **/\r
- public void setFileName(String fileName) {\r
- this.fileName = fileName; \r
- }\r
-\r
- public int getAlignment() {\r
- return alignment;\r
- }\r
-\r
- public void setAlignment(int alignment) {\r
- if (alignment > 7) {\r
- this.alignment = 7;\r
- } else {\r
- this.alignment = alignment;\r
- }\r
- }\r
-\r
- public SectFile (){\r
- }\r
-\r
- /**\r
- Put the content of section file into specified buffer with extra bytes for \r
- alignment requirement.\r
- \r
- @param Buffer buffer to contain the section file content with alignment\r
- **/\r
- public void toBuffer (DataOutputStream buffer){\r
- File sectFile;\r
- int fileLen;\r
-\r
- ///\r
- /// open file\r
- ///\r
- sectFile = new File (this.fileName); \r
-\r
- ///\r
- /// check if file exist.\r
- /// \r
- if (! sectFile.exists()) {\r
- throw new BuildException("The file " + this.fileName + " is not exist!\n"); \r
- }\r
-\r
-\r
- ///\r
- /// Read section file and add it's contains to buffer.\r
- ///\r
- try {\r
-\r
- FileInputStream fs = new FileInputStream (sectFile.getAbsoluteFile());\r
- DataInputStream In = new DataInputStream (fs);\r
- fileLen = (int)sectFile.length();\r
- byte[] sectBuffer = new byte[fileLen];\r
- In.read(sectBuffer);\r
- buffer.write(sectBuffer);\r
-\r
- ///\r
- /// 4 byte alignment\r
- ///\r
- while ((fileLen & 0x03)!= 0) {\r
- fileLen ++;\r
- buffer.writeByte(0);\r
- } \r
-\r
- ///\r
- /// close inputStream\r
- ///\r
- In.close();\r
-\r
- } catch (Exception e) {\r
- System.out.print(e.getMessage());\r
- throw new BuildException("SectFile, toBuffer failed!\n"); \r
- }\r
- }\r
-}
\ No newline at end of file