]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Java class CreateFdp is used to create a distributable package containing \r | |
3 | FDPManifest.xml file in its root directory.\r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | **/\r | |
14 | package org.tianocore.packaging;\r | |
15 | \r | |
16 | import java.io.*;\r | |
17 | import java.util.jar.*;\r | |
18 | \r | |
19 | /**\r | |
20 | This class contains static method create to generate *.fdp format package.\r | |
21 | \r | |
22 | @since PackageEditor 1.0\r | |
23 | **/\r | |
24 | public class CreateFdp {\r | |
25 | \r | |
26 | /**\r | |
27 | recursively add contents under dir into output package.\r | |
28 | \r | |
29 | @param dir The directory with files that will be put into package\r | |
30 | @param jos Stream used to create output package\r | |
31 | @param wkDir The position of source directory\r | |
32 | @throws Exception Any exception occurred during this process\r | |
33 | **/\r | |
34 | public static void create(File dir, JarOutputStream jos, String wkDir) throws Exception {\r | |
35 | \r | |
36 | String[] list = dir.list();\r | |
37 | \r | |
38 | try {\r | |
39 | byte[] buffer = new byte[1024];\r | |
40 | int bytesRead;\r | |
41 | \r | |
42 | //\r | |
43 | // Loop through the file names provided.\r | |
44 | //\r | |
45 | for (int i = 0; i < list.length; i++) {\r | |
46 | \r | |
47 | File f = new File(dir, list[i]);\r | |
48 | if (f.getName().equals("..")) {\r | |
49 | continue;\r | |
50 | }\r | |
51 | if (f.isDirectory()) {\r | |
52 | //\r | |
53 | // Call this method recursively for directory\r | |
54 | //\r | |
55 | CreateFdp.create(f, jos, wkDir);\r | |
56 | continue;\r | |
57 | }\r | |
58 | \r | |
59 | try {\r | |
60 | //\r | |
61 | // Open the file\r | |
62 | //\r | |
63 | FileInputStream fis = new FileInputStream(f);\r | |
64 | \r | |
65 | try {\r | |
66 | //\r | |
67 | // Create a Jar entry and add it, keep relative path only.\r | |
68 | //\r | |
69 | JarEntry entry = new JarEntry(f.getPath().substring(wkDir.length() + 1));\r | |
70 | jos.putNextEntry(entry);\r | |
71 | \r | |
72 | //\r | |
73 | // Read the file and write it to the Jar.\r | |
74 | //\r | |
75 | while ((bytesRead = fis.read(buffer)) != -1) {\r | |
76 | jos.write(buffer, 0, bytesRead);\r | |
77 | }\r | |
78 | \r | |
79 | System.out.println(entry.getName() + " added.");\r | |
80 | } catch (Exception ex) {\r | |
81 | System.out.println(ex);\r | |
82 | } finally {\r | |
83 | fis.close();\r | |
84 | }\r | |
85 | } catch (IOException ex) {\r | |
86 | System.out.println(ex);\r | |
87 | }\r | |
88 | }\r | |
89 | } finally {\r | |
90 | System.out.println(dir.getPath() + " processed.");\r | |
91 | }\r | |
92 | }\r | |
93 | }\r |