]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java
1. Adjust might be 64bit, so we need to typecast it to UINT32 firstly.
[mirror_edk2.git] / Tools / 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\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, DataOutputStream orgBuffer){\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 + " does 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 //\r
88 // Add data to org file \r
89 //\r
90 orgBuffer.writeByte(data);\r
91 i++;\r
92 }\r
93\r
94 ///\r
95 /// 4 byte alignment\r
96 ///\r
97 while ((fileLen & 0x03)!= 0) {\r
98 fileLen ++;\r
99 buffer.writeByte(0);\r
100 //\r
101 // Add data to org file \r
102 //\r
103 orgBuffer.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}\r