]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java
Initial import.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / SectFile.java
CommitLineData
878ddf1f 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\r
29 /**\r
30 Get method of ANT task/datatype for "FileName" attribute\r
31 \r
32 @returns The name of section file\r
33 **/\r
34 public String getFileName() {\r
35 return fileName;\r
36 }\r
37\r
38 /**\r
39 Set method of ANT task/datatype for "FileName" attribute\r
40 \r
41 @param fileName The name of section file\r
42 **/\r
43 public void setFileName(String fileName) {\r
44 this.fileName = fileName; \r
45 }\r
46\r
47 public SectFile (){\r
48 }\r
49\r
50 /**\r
51 Put the content of section file into specified buffer with extra bytes for \r
52 alignment requirement.\r
53 \r
54 @param Buffer buffer to contain the section file content with alignment\r
55 **/\r
56 public void toBuffer (DataOutputStream Buffer){\r
57 File sectFile;\r
58 byte data;\r
59 long fileLen;\r
60\r
61 ///\r
62 /// open file\r
63 ///\r
64 sectFile = new File (this.fileName); \r
65\r
66 ///\r
67 /// check if file exist.\r
68 /// \r
69 if (! sectFile.exists()) {\r
70 throw new BuildException("The file " + this.fileName + " is not exist!\n"); \r
71 }\r
72\r
73\r
74 ///\r
75 /// Read section file and add it's contains to buffer.\r
76 ///\r
77 try {\r
78\r
79 FileInputStream fs = new FileInputStream (sectFile.getAbsoluteFile());\r
80 DataInputStream In = new DataInputStream (fs);\r
81 fileLen = sectFile.length();\r
82\r
83 int i = 0;\r
84 while (i < fileLen) {\r
85 data = In.readByte();\r
86 Buffer.writeByte(data);\r
87 i++;\r
88 }\r
89\r
90 ///\r
91 /// 4 byte alignment\r
92 ///\r
93 while ((fileLen & 0x03)!= 0) {\r
94 fileLen ++;\r
95 Buffer.writeByte(0);\r
96 } \r
97\r
98 ///\r
99 /// close inputStream\r
100 ///\r
101 In.close();\r
102\r
103 } catch (Exception e) {\r
104 System.out.print(e.getMessage());\r
105 throw new BuildException("section file2Buffer failed!\n"); \r
106 }\r
107 }\r
108}