1 5 package SOFA.SOFAnode.TR.Impl; 6 7 import java.io.File ; 8 import java.io.FileOutputStream ; 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.util.Date ; 12 import java.util.jar.JarEntry ; 13 import java.util.jar.JarInputStream ; 14 15 import SOFA.Util.Tools; 16 17 25 class BundleInputStream extends JarInputStream { 26 27 33 private File tempDir; 34 35 38 private JarEntry lastEntry; 39 40 43 private String lastName; 44 45 48 private boolean eof; 49 50 54 private String lastPrefix; 55 56 62 public BundleInputStream (InputStream in) throws IOException { 63 super(in, false); 64 tempDir = new File (System.getProperty("java.io.tmpdir") + File.separator + "sofa" + Long.toString(new Date ().getTime()) + ".bar"); 65 tempDir.mkdir(); 66 lastEntry = null; 67 lastPrefix = null; 68 lastName = null; 69 eof = false; 70 } 71 72 79 public BundleEntry getNextBundleEntry () throws IOException { 80 if (eof) return null; 82 if (lastEntry == null) { lastEntry = getNextJarEntry(); 84 if (lastEntry == null) { eof = true; 86 return null; 87 } 88 lastName = lastEntry.getName(); lastPrefix = lastName.substring(0, lastName.indexOf('/')); } 91 BundleEntry bundleEntry = new BundleEntry(lastPrefix); 92 for (; ;) { 93 String path = lastName.substring(0, lastName.lastIndexOf("/")); path = path.replace('/', File.separatorChar); File file = new File (tempDir, path); 96 file.mkdirs(); 97 file = new File (tempDir, lastName); 98 FileOutputStream outFile = new FileOutputStream (file); 99 100 Tools.copyStream(this, outFile); 101 102 super.closeEntry(); 103 outFile.close(); 104 file.setLastModified(lastEntry.getTime()); String hashName = lastName.substring(lastPrefix.length()); bundleEntry.addFile(file, hashName); 107 lastEntry = getNextJarEntry(); 108 if (lastEntry == null) { eof = true; 110 return bundleEntry; 111 } 112 lastName = lastEntry.getName(); String newPrefix = lastName.substring(0, lastName.indexOf('/')); if (!lastPrefix.equals(newPrefix)) { 115 lastPrefix = newPrefix; 116 return bundleEntry; 117 } 118 } 119 } 120 121 127 File getTempRootDirectory () { 128 return tempDir; 129 } 130 } 131 | Popular Tags |