]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/Far.java
1. Update release note to use jdk1.5.0_06 to take place of jdk1.5.0_04
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / Far.java
index 21a86f5789651dbd8830c8d427ef87240964ee66..57116334f2fd9a1ded4082b49da10ba0ffb2cc86 100644 (file)
@@ -154,6 +154,39 @@ public class Far {
         return true;\r
     }\r
 \r
+    //    public static void main(String[] args){\r
+    //        try {\r
+    //            JarFile jarFile = new JarFile(new File("C:\\cvswork\\newEdk\\jar.jar.far"));\r
+    //            JarEntry je= jarFile.getJarEntry("MdePkg/MdePkg.spd");\r
+    //            InputStream is = jarFile.getInputStream(je);\r
+    //            byte[] buffer = new byte[1];      \r
+    //            File tempFile = new File("C:\\cvswork\\newEdk\\tempFile");\r
+    //            File tfile2 = new File("C:\\cvswork\\newEdk\\tempFile1");\r
+    //            FileOutputStream fos1 = new FileOutputStream(tfile2);\r
+    //            FileOutputStream fos = new FileOutputStream(tempFile);\r
+    //            int size = is.read(buffer);\r
+    //            int totoalSize = size;\r
+    //            while ( size >=  0) {\r
+    //                fos.write(buffer);\r
+    //                size = is.read(buffer);\r
+    //                totoalSize = totoalSize + size;\r
+    //            }\r
+    //            \r
+    //            \r
+    ////            is = jarFile.getInputStream(je);\r
+    ////            is.read(totalbuffer);\r
+    ////            fos.write(totalbuffer);\r
+    //            fos.close();\r
+    //            byte[] totalbuffer = new byte[(int)tempFile.length()];\r
+    //            FileInputStream fis = new FileInputStream(tempFile);\r
+    //            fis.read(totalbuffer);\r
+    //            fos1.write(totalbuffer);\r
+    //            fos1.close();\r
+    //        }catch(Exception e){\r
+    //            \r
+    //        }\r
+    //    }\r
+\r
     public void extract(List<FarFileItem> allFile, String dir) throws Exception {\r
 \r
         Iterator filesItem = allFile.iterator();\r
@@ -164,10 +197,6 @@ public class Far {
         while (filesItem.hasNext()) {\r
             try {\r
                 ffItem = (FarFileItem) filesItem.next();\r
-                //                Enumeration<JarEntry> a = jf.entries();\r
-                //                while (a.hasMoreElements()) {\r
-                //                    System.out.println("##" + a.nextElement().getName());\r
-                //                }\r
                 je = jf.getJarEntry(Tools.convertPathToUnixType(ffItem.getDefaultPath()));\r
                 InputStream entryStream = jf.getInputStream(je);\r
                 File file = new File(dir + ffItem.getRelativeFilename());\r
@@ -184,14 +213,22 @@ public class Far {
                         // Read the entry data and write it to the output\r
                         // file.\r
                         //\r
-                        int size = entryStream.available();\r
-                        byte[] buffer = new byte[size];\r
-                        outputStream.write(buffer);\r
-                        //                        if (!(FarMd5.md5(buffer)).equalsIgnoreCase(ffItem.getMd5Value())){\r
-                        //                            throw new Exception (je.getName() + " Md5 is invalided!");\r
-                        //                        }\r
-\r
-                        //                        System.out.println(je.getName() + " extracted.");\r
+                        byte[] buffer = new byte[1];\r
+                        File tempFile = new File("tempFile");\r
+                        FileOutputStream fos = new FileOutputStream(tempFile);\r
+                        int size = entryStream.read(buffer);\r
+                        while (size >= 0) {\r
+                            fos.write(buffer);\r
+                            size = entryStream.read(buffer);\r
+                        }\r
+\r
+                        fos.close();\r
+                        byte[] totalBuffer = new byte[(int) tempFile.length()];\r
+                        FileInputStream fis = new FileInputStream(tempFile);\r
+                        fis.read(totalBuffer);\r
+                        outputStream.write(totalBuffer);\r
+                        fis.close();\r
+                        tempFile.delete();\r
                     } finally {\r
                         outputStream.close();\r
                     }\r
@@ -200,24 +237,11 @@ public class Far {
                 }\r
 \r
             } finally {\r
-                //jf.close();\r
             }\r
         }\r
 \r
     }\r
 \r
-    //    public void installFarPackage (PackageIdentification pkgId, String dir) throws Exception{\r
-    //        String pkgDir = null;\r
-    //        List<FarFileItem> farFileList = new ArrayList<FarFileItem>();\r
-    //        farFileList = this.mainfest.getPackageContents(pkgId);\r
-    //        if (dir == null){\r
-    //            pkgDir = this.mainfest.getPackageDefaultPath(pkgId);\r
-    //        }else {\r
-    //            pkgDir = dir;\r
-    //        }\r
-    //        extract(farFileList,pkgDir);\r
-    //    }\r
-\r
     public void addFileToFar(File file, JarOutputStream farOuputStream, String workDir) {\r
 \r
     }\r
@@ -233,6 +257,9 @@ public class Far {
         List<PackageIdentification> result = new ArrayList<PackageIdentification>();\r
 \r
         entry = this.mainfest.getPackgeSpd(pkgId);\r
+        if (entry == null) {\r
+            return result;\r
+        }\r
         if (entry[0] != null) {\r
             try {\r
                 JarEntry je;\r