1 11 package org.eclipse.jdt.internal.core; 12 13 import java.io.ByteArrayInputStream ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.util.zip.ZipEntry ; 17 import java.util.zip.ZipFile ; 18 19 import org.eclipse.core.resources.IStorage; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.jdt.core.IJarEntryResource; 22 import org.eclipse.jdt.core.IJavaModelStatusConstants; 23 import org.eclipse.jdt.core.JavaModelException; 24 import org.eclipse.jdt.internal.compiler.util.Util; 25 26 31 public class JarEntryFile extends JarEntryResource { 32 private static final IJarEntryResource[] NO_CHILDREN = new IJarEntryResource[0]; 33 34 public JarEntryFile(String simpleName) { 35 super(simpleName); 36 } 37 38 public JarEntryResource clone(Object newParent) { 39 JarEntryFile file = new JarEntryFile(simpleName); 40 file.setParent(newParent); 41 return file; 42 } 43 44 public InputStream getContents() throws CoreException { 45 ZipFile zipFile = null; 46 try { 47 zipFile = getZipFile(); 48 if (JavaModelManager.ZIP_ACCESS_VERBOSE) { 49 System.out.println("(" + Thread.currentThread() + ") [JarEntryFile.getContents()] Creating ZipFile on " +zipFile.getName()); } 51 String entryName = getEntryName(); 52 ZipEntry zipEntry = zipFile.getEntry(entryName); 53 if (zipEntry == null){ 54 throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, entryName)); 55 } 56 byte[] contents = Util.getZipEntryByteContent(zipEntry, zipFile); 57 return new ByteArrayInputStream (contents); 58 } catch (IOException e){ 59 throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); 60 } finally { 61 JavaModelManager.getJavaModelManager().closeZipFile(zipFile); 63 } 64 } 65 66 public IJarEntryResource[] getChildren() { 67 return NO_CHILDREN; 68 } 69 70 public boolean isFile() { 71 return true; 72 } 73 74 public String toString() { 75 return "JarEntryFile["+getEntryName()+"]"; } 77 } 78 | Popular Tags |