Modify Extract() function to speed up the Far installation.
authorqouyang <qouyang@de2fecce-e211-0410-80a6-f3fac2684e05>
Thu, 12 Oct 2006 10:19:59 +0000 (10:19 +0000)
committerqouyang <qouyang@de2fecce-e211-0410-80a6-f3fac2684e05>
Thu, 12 Oct 2006 10:19:59 +0000 (10:19 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@1729 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/Far.java

index 6dbf1af..ad04dc7 100644 (file)
@@ -154,39 +154,6 @@ 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
@@ -213,28 +180,30 @@ public class Far {
                         // Read the entry data and write it to the output\r
                         // file.\r
                         //\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
+                        int fileLen = (int)je.getSize();\r
+                        byte[] buffer = new byte[fileLen];\r
+                        int len = entryStream.read(buffer);\r
+                        if (len < fileLen){\r
+                            File tempFile = new File("tempFile");\r
+                            FileOutputStream fos = new FileOutputStream(tempFile);\r
+                            fos.write(buffer, 0, len);\r
+                            while (len < fileLen){\r
+                                int tempLen = entryStream.read(buffer);\r
+                                len = len + tempLen;\r
+                                fos.write(buffer, 0, tempLen);\r
+                            }\r
+                            fos.close();\r
+                            FileInputStream fin = new FileInputStream(tempFile);\r
+                            fin.read(buffer);\r
+                            tempFile.delete();\r
                         }\r
-\r
-                        fos.close();\r
-                        byte[] totalBuffer = new byte[(int) tempFile.length()];\r
-                        FileInputStream fis = new FileInputStream(tempFile);\r
-                        fis.read(totalBuffer);\r
                         //\r
                         //  Check Md5\r
                         //\r
-                        if (!ffItem.getMd5Value().equalsIgnoreCase(FarMd5.md5(totalBuffer))){\r
+                        if (!ffItem.getMd5Value().equalsIgnoreCase(FarMd5.md5(buffer))){\r
                             throw new Exception (ffItem.getRelativeFilename() + " MD5 Checksum is invaild!");\r
                         }\r
-                        outputStream.write(totalBuffer);\r
-                        fis.close();\r
-                        tempFile.delete();\r
+                        outputStream.write(buffer);\r
                     } finally {\r
                         outputStream.close();\r
                     }\r