KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > JarEntryFile


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor;
12
13 import java.io.File JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.util.zip.ZipEntry JavaDoc;
16 import java.util.zip.ZipFile JavaDoc;
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 JavaDoc fZipFile;
31     private String JavaDoc fEntryName;
32
33     public JarEntryFile(ZipFile JavaDoc zipFile, String JavaDoc entryName) {
34         fZipFile = zipFile;
35         fEntryName = entryName;
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.core.resources.IStorage#getContents()
40      */

41     public InputStream JavaDoc getContents() throws CoreException {
42         try {
43             ZipEntry JavaDoc zipEntry = fZipFile.getEntry(fEntryName);
44             return fZipFile.getInputStream(zipEntry);
45         } catch (Exception JavaDoc e){
46             throw new CoreException(new Status(IStatus.ERROR, IPDEUIConstants.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
47         }
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.core.resources.IStorage#getFullPath()
52      */

53     public IPath getFullPath() {
54         return new Path(fEntryName);
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.core.resources.IStorage#getName()
59      */

60     public String JavaDoc getName() {
61         return getFullPath().lastSegment();
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.core.resources.IStorage#isReadOnly()
66      */

67     public boolean isReadOnly() {
68         return true;
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
73      */

74     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
75         if (adapter.equals(ZipFile JavaDoc.class))
76             return fZipFile;
77         if (adapter.equals(File JavaDoc.class))
78             return new File JavaDoc(fZipFile.getName());
79         return super.getAdapter(adapter);
80     }
81     
82     public String JavaDoc toString() {
83         return "JarEntryFile["+ fZipFile.getName() + "::" + fEntryName + "]"; //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
84
}
85     
86     public boolean equals(Object JavaDoc obj) {
87         if (!(obj instanceof JarEntryFile))
88             return false;
89         return toString().equals(obj.toString());
90     }
91
92 }
93
Popular Tags