jf = farFile;\r
this.mainfest = new Mainfest(getMainfestFile());\r
}\r
-\r
- public void creatFar(List<PackageIdentification> pkgList, List<PlatformIdentification> plfList,\r
- Set<String> fileFilter, FarHeader fHeader) throws Exception {\r
+ \r
+ public void creatFar (List<PackageIdentification> pkgList,\r
+ List<PlatformIdentification> plfList, Set<String> fileFilter,\r
+ FarHeader fHeader) throws Exception{\r
jos = new JarOutputStream(new FileOutputStream(jarFile));\r
\r
//\r
}\r
jos.close();\r
}\r
-\r
- private void writeToJar(File file, JarOutputStream jos) throws Exception {\r
- byte[] buffer = new byte[(int) file.length()];\r
- FileInputStream fInput = new FileInputStream(file);\r
- JarEntry entry = new JarEntry(\r
- Tools\r
- .convertPathToUnixType(Tools\r
- .getRelativePath(file.getPath(),\r
- Workspace.getCurrentWorkspace())));\r
- jos.putNextEntry(entry);\r
- fInput.read(buffer);\r
- jos.write(buffer);\r
- fInput.close();\r
+ \r
+ private void writeToJar(File file, JarOutputStream jos) throws Exception{\r
+ byte[] buffer = new byte[(int)file.length()];\r
+ FileInputStream fInput = new FileInputStream(file);\r
+ JarEntry entry = new JarEntry(Tools.convertPathToUnixType(Tools.getRelativePath(file.getPath(),Workspace.getCurrentWorkspace())));\r
+ jos.putNextEntry(entry);\r
+ fInput.read(buffer);\r
+ jos.write(buffer);\r
+ fInput.close();\r
}\r
\r
public void InstallFar(String dir) throws Exception {\r
List<FarFileItem> allFile = mainfest.getAllFileItem();\r
extract(allFile, dir);\r
}\r
-\r
- public void InstallFar(Map<PlatformIdentification, File> plfMap, Map<PackageIdentification, File> pkgMap)\r
- throws Exception {\r
+ \r
+ public void InstallFar (Map<PlatformIdentification, File> plfMap, Map<PackageIdentification, File> pkgMap) throws Exception{\r
Set<PlatformIdentification> plfKeys = plfMap.keySet();\r
Iterator<PlatformIdentification> plfIter = plfKeys.iterator();\r
while (plfIter.hasNext()) {\r
public boolean hibernateToFile() {\r
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
dir += File.separatorChar;\r
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
+ ffItem = (FarFileItem)filesItem.next();\r
je = jf.getJarEntry(Tools.convertPathToUnixType(ffItem.getDefaultPath()));\r
InputStream entryStream = jf.getInputStream(je);\r
File file = new File(dir + ffItem.getRelativeFilename());\r
// exists).\r
//\r
FileOutputStream outputStream = new FileOutputStream(file);\r
+ \r
\r
try {\r
//\r
// 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
}\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
+ }\r
+ \r
+ \r
+ public void addFileToFar (File file, JarOutputStream farOuputStream, String workDir){\r
+ \r
}\r
\r
/**\r