]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/CreateFdp.java
2 Java class CreateFdp is used to create a distributable package containing
3 FDPManifest.xml file in its root directory.
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.packaging
;
17 import java
.util
.jar
.*;
20 This class contains static method create to generate *.fdp format package.
22 @since PackageEditor 1.0
24 public class CreateFdp
{
27 recursively add contents under dir into output package.
29 @param dir The directory with files that will be put into package
30 @param jos Stream used to create output package
31 @param wkDir The position of source directory
32 @throws Exception Any exception occurred during this process
34 public static void create(File dir
, JarOutputStream jos
, String wkDir
) throws Exception
{
36 String
[] list
= dir
.list();
39 byte[] buffer
= new byte[1024];
43 // Loop through the file names provided.
45 for (int i
= 0; i
< list
.length
; i
++) {
47 File f
= new File(dir
, list
[i
]);
48 if (f
.getName().equals("..")) {
51 if (f
.isDirectory()) {
53 // Call this method recursively for directory
55 CreateFdp
.create(f
, jos
, wkDir
);
63 FileInputStream fis
= new FileInputStream(f
);
67 // Create a Jar entry and add it, keep relative path only.
69 JarEntry entry
= new JarEntry(f
.getPath().substring(wkDir
.length() + 1));
70 jos
.putNextEntry(entry
);
73 // Read the file and write it to the Jar.
75 while ((bytesRead
= fis
.read(buffer
)) != -1) {
76 jos
.write(buffer
, 0, bytesRead
);
79 System
.out
.println(entry
.getName() + " added.");
80 } catch (Exception ex
) {
81 System
.out
.println(ex
);
85 } catch (IOException ex
) {
86 System
.out
.println(ex
);
90 System
.out
.println(dir
.getPath() + " processed.");