]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java
- Fixed EDKT240. Now the Blank.pad file for alignment purpose will no longer be needed.
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / SectFile.java
... / ...
CommitLineData
1/** @file\r
2This file is to define nested element which is meant for specifying section file\r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14package org.tianocore.framework.tasks;\r
15\r
16import java.io.DataInputStream;\r
17import java.io.DataOutputStream;\r
18import java.io.File;\r
19import java.io.FileInputStream;\r
20import org.apache.tools.ant.BuildException;\r
21\r
22/**\r
23 Class SectFile is to define a class corresponding to ANT nested element. It's\r
24 used to specify section file(s) when used with GenFfsFile task\r
25 **/\r
26public class SectFile implements Section {\r
27 private String fileName = ""; /// section file name\r
28 private int alignment = 0;\r
29\r
30 /**\r
31 Get method of ANT task/datatype for "FileName" attribute\r
32 \r
33 @returns The name of section file\r
34 **/\r
35 public String getFileName() {\r
36 return fileName;\r
37 }\r
38\r
39 /**\r
40 Set method of ANT task/datatype for "FileName" attribute\r
41 \r
42 @param fileName The name of section file\r
43 **/\r
44 public void setFileName(String fileName) {\r
45 this.fileName = fileName; \r
46 }\r
47\r
48 public int getAlignment() {\r
49 return alignment;\r
50 }\r
51\r
52 public void setAlignment(int alignment) {\r
53 if (alignment > 7) {\r
54 this.alignment = 7;\r
55 } else {\r
56 this.alignment = alignment;\r
57 }\r
58 }\r
59\r
60 public SectFile (){\r
61 }\r
62\r
63 /**\r
64 Put the content of section file into specified buffer with extra bytes for \r
65 alignment requirement.\r
66 \r
67 @param Buffer buffer to contain the section file content with alignment\r
68 **/\r
69 public void toBuffer (DataOutputStream buffer){\r
70 File sectFile;\r
71 int fileLen;\r
72\r
73 ///\r
74 /// open file\r
75 ///\r
76 sectFile = new File (this.fileName); \r
77\r
78 ///\r
79 /// check if file exist.\r
80 /// \r
81 if (! sectFile.exists()) {\r
82 throw new BuildException("The file " + this.fileName + " is not exist!\n"); \r
83 }\r
84\r
85\r
86 ///\r
87 /// Read section file and add it's contains to buffer.\r
88 ///\r
89 try {\r
90\r
91 FileInputStream fs = new FileInputStream (sectFile.getAbsoluteFile());\r
92 DataInputStream In = new DataInputStream (fs);\r
93 fileLen = (int)sectFile.length();\r
94 byte[] sectBuffer = new byte[fileLen];\r
95 In.read(sectBuffer);\r
96 buffer.write(sectBuffer);\r
97\r
98 ///\r
99 /// 4 byte alignment\r
100 ///\r
101 while ((fileLen & 0x03)!= 0) {\r
102 fileLen ++;\r
103 buffer.writeByte(0);\r
104 } \r
105\r
106 ///\r
107 /// close inputStream\r
108 ///\r
109 In.close();\r
110\r
111 } catch (Exception e) {\r
112 System.out.print(e.getMessage());\r
113 throw new BuildException("SectFile, toBuffer failed!\n"); \r
114 }\r
115 }\r
116}