1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import java.io.File ; 14 import java.io.InputStream ; 15 import java.util.zip.ZipEntry ; 16 import java.util.zip.ZipFile ; 17 18 import org.eclipse.core.resources.IStorage; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IPath; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Path; 23 import org.eclipse.core.runtime.PlatformObject; 24 import org.eclipse.core.runtime.Status; 25 import org.eclipse.pde.internal.ui.IPDEUIConstants; 26 27 28 public class JarEntryFile extends PlatformObject implements IStorage { 29 30 private ZipFile fZipFile; 31 private String fEntryName; 32 33 public JarEntryFile(ZipFile zipFile, String entryName) { 34 fZipFile = zipFile; 35 fEntryName = entryName; 36 } 37 38 41 public InputStream getContents() throws CoreException { 42 try { 43 ZipEntry zipEntry = fZipFile.getEntry(fEntryName); 44 return fZipFile.getInputStream(zipEntry); 45 } catch (Exception e){ 46 throw new CoreException(new Status(IStatus.ERROR, IPDEUIConstants.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); 47 } 48 } 49 50 53 public IPath getFullPath() { 54 return new Path(fEntryName); 55 } 56 57 60 public String getName() { 61 return getFullPath().lastSegment(); 62 } 63 64 67 public boolean isReadOnly() { 68 return true; 69 } 70 71 74 public Object getAdapter(Class adapter) { 75 if (adapter.equals(ZipFile .class)) 76 return fZipFile; 77 if (adapter.equals(File .class)) 78 return new File (fZipFile.getName()); 79 return super.getAdapter(adapter); 80 } 81 82 public String toString() { 83 return "JarEntryFile["+ fZipFile.getName() + "::" + fEntryName + "]"; } 85 86 public boolean equals(Object obj) { 87 if (!(obj instanceof JarEntryFile)) 88 return false; 89 return toString().equals(obj.toString()); 90 } 91 92 } 93 | Popular Tags |