Modify Extract() function to speed up the Far installation.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1729 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qouyang 2006-10-12 10:19:59 +00:00
parent fbf730ff01
commit 046d7d4f1d
1 changed files with 18 additions and 49 deletions

View File

@ -154,39 +154,6 @@ public class Far {
return true; return true;
} }
// public static void main(String[] args){
// try {
// JarFile jarFile = new JarFile(new File("C:\\cvswork\\newEdk\\jar.jar.far"));
// JarEntry je= jarFile.getJarEntry("MdePkg/MdePkg.spd");
// InputStream is = jarFile.getInputStream(je);
// byte[] buffer = new byte[1];
// File tempFile = new File("C:\\cvswork\\newEdk\\tempFile");
// File tfile2 = new File("C:\\cvswork\\newEdk\\tempFile1");
// FileOutputStream fos1 = new FileOutputStream(tfile2);
// FileOutputStream fos = new FileOutputStream(tempFile);
// int size = is.read(buffer);
// int totoalSize = size;
// while ( size >= 0) {
// fos.write(buffer);
// size = is.read(buffer);
// totoalSize = totoalSize + size;
// }
//
//
//// is = jarFile.getInputStream(je);
//// is.read(totalbuffer);
//// fos.write(totalbuffer);
// fos.close();
// byte[] totalbuffer = new byte[(int)tempFile.length()];
// FileInputStream fis = new FileInputStream(tempFile);
// fis.read(totalbuffer);
// fos1.write(totalbuffer);
// fos1.close();
// }catch(Exception e){
//
// }
// }
public void extract(List<FarFileItem> allFile, String dir) throws Exception { public void extract(List<FarFileItem> allFile, String dir) throws Exception {
Iterator filesItem = allFile.iterator(); Iterator filesItem = allFile.iterator();
@ -213,28 +180,30 @@ public class Far {
// Read the entry data and write it to the output // Read the entry data and write it to the output
// file. // file.
// //
byte[] buffer = new byte[1]; int fileLen = (int)je.getSize();
File tempFile = new File("tempFile"); byte[] buffer = new byte[fileLen];
FileOutputStream fos = new FileOutputStream(tempFile); int len = entryStream.read(buffer);
int size = entryStream.read(buffer); if (len < fileLen){
while (size >= 0) { File tempFile = new File("tempFile");
fos.write(buffer); FileOutputStream fos = new FileOutputStream(tempFile);
size = entryStream.read(buffer); fos.write(buffer, 0, len);
while (len < fileLen){
int tempLen = entryStream.read(buffer);
len = len + tempLen;
fos.write(buffer, 0, tempLen);
}
fos.close();
FileInputStream fin = new FileInputStream(tempFile);
fin.read(buffer);
tempFile.delete();
} }
fos.close();
byte[] totalBuffer = new byte[(int) tempFile.length()];
FileInputStream fis = new FileInputStream(tempFile);
fis.read(totalBuffer);
// //
// Check Md5 // Check Md5
// //
if (!ffItem.getMd5Value().equalsIgnoreCase(FarMd5.md5(totalBuffer))){ if (!ffItem.getMd5Value().equalsIgnoreCase(FarMd5.md5(buffer))){
throw new Exception (ffItem.getRelativeFilename() + " MD5 Checksum is invaild!"); throw new Exception (ffItem.getRelativeFilename() + " MD5 Checksum is invaild!");
} }
outputStream.write(totalBuffer); outputStream.write(buffer);
fis.close();
tempFile.delete();
} finally { } finally {
outputStream.close(); outputStream.close();
} }