1 11 package org.eclipse.debug.core.sourcelookup.containers; 12 13 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.core.runtime.IPath; 22 import org.eclipse.core.runtime.IStatus; 23 import org.eclipse.core.runtime.Path; 24 import org.eclipse.core.runtime.PlatformObject; 25 import org.eclipse.core.runtime.Status; 26 import org.eclipse.debug.core.DebugPlugin; 27 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; 28 29 37 public class ZipEntryStorage extends PlatformObject implements IStorage { 38 39 42 private ZipFile fArchive; 43 44 47 private ZipEntry fZipEntry; 48 49 56 public ZipEntryStorage(ZipFile archive, ZipEntry entry) { 57 setArchive(archive); 58 setZipEntry(entry); 59 } 60 61 64 public InputStream getContents() throws CoreException { 65 try { 66 return getArchive().getInputStream(getZipEntry()); 67 } catch (IOException e) { 68 throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, SourceLookupMessages.ZipEntryStorage_0, e)); 69 } 70 } 71 72 75 public IPath getFullPath() { 76 return new Path(getArchive().getName()).append(getZipEntry().getName()); 77 } 78 79 82 public String getName() { 83 int index = getZipEntry().getName().lastIndexOf('\\'); 84 if (index == -1) { 85 index = getZipEntry().getName().lastIndexOf('/'); 86 } 87 if (index == -1) { 88 return getZipEntry().getName(); 89 } 90 return getZipEntry().getName().substring(index + 1); 91 } 92 93 96 public boolean isReadOnly() { 97 return true; 98 } 99 100 105 private void setArchive(ZipFile archive) { 106 fArchive = archive; 107 } 108 109 114 public ZipFile getArchive() { 115 return fArchive; 116 } 117 118 123 private void setZipEntry(ZipEntry entry) { 124 fZipEntry = entry; 125 } 126 127 132 public ZipEntry getZipEntry() { 133 return fZipEntry; 134 } 135 136 139 public boolean equals(Object object) { 140 return object instanceof ZipEntryStorage && 141 getArchive().equals(((ZipEntryStorage)object).getArchive()) && 142 getZipEntry().getName().equals(((ZipEntryStorage)object).getZipEntry().getName()); 143 } 144 145 148 public int hashCode() { 149 return getZipEntry().getName().hashCode(); 150 } 151 } 152 | Popular Tags |