KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > baseadaptor > bundlefile > ZipBundleEntry


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.osgi.baseadaptor.bundlefile;
12
13 import java.io.*;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.zip.ZipEntry JavaDoc;
17
18 /**
19  * A BundleEntry represented by a ZipEntry in a ZipFile. The ZipBundleEntry
20  * class is used for bundles that are installed as a ZipFile on a file system.
21  * @since 3.2
22  */

23 public class ZipBundleEntry extends BundleEntry {
24     /**
25      * ZipEntry for this entry.
26      */

27     protected ZipEntry JavaDoc zipEntry;
28
29     /**
30      * The BundleFile for this entry.
31      */

32     protected BundleFile bundleFile;
33
34     /**
35      * Constructs the BundleEntry using a ZipEntry.
36      * @param bundleFile BundleFile object this entry is a member of
37      * @param zipEntry ZipEntry object of this entry
38      */

39     ZipBundleEntry(ZipEntry JavaDoc zipEntry, BundleFile bundleFile) {
40         this.zipEntry = zipEntry;
41         this.bundleFile = bundleFile;
42     }
43
44     /**
45      * Return an InputStream for the entry.
46      *
47      * @return InputStream for the entry
48      * @exception java.io.IOException
49      */

50     public InputStream getInputStream() throws IOException {
51         return ((ZipBundleFile) bundleFile).getZipFile().getInputStream(zipEntry);
52     }
53
54     /**
55      * Return size of the uncompressed entry.
56      *
57      * @return size of entry
58      */

59     public long getSize() {
60         return zipEntry.getSize();
61     }
62
63     /**
64      * Return name of the entry.
65      *
66      * @return name of entry
67      */

68     public String JavaDoc getName() {
69         return zipEntry.getName();
70     }
71
72     /**
73      * Get the modification time for this BundleEntry.
74      * <p>If the modification time has not been set,
75      * this method will return <tt>-1</tt>.
76      *
77      * @return last modification time.
78      */

79     public long getTime() {
80         return zipEntry.getTime();
81     }
82
83     public URL JavaDoc getLocalURL() {
84         try {
85             return new URL JavaDoc("jar:file:" + bundleFile.basefile.getAbsolutePath() + "!/" + zipEntry.getName()); //$NON-NLS-1$//$NON-NLS-2$
86
} catch (MalformedURLException JavaDoc e) {
87             //This can not happen.
88
return null;
89         }
90     }
91
92     public URL JavaDoc getFileURL() {
93         try {
94             File file = bundleFile.getFile(zipEntry.getName(), false);
95             if (file != null)
96                 return file.toURL();
97         } catch (MalformedURLException JavaDoc e) {
98             //This can not happen.
99
}
100         return null;
101     }
102 }
103
Popular Tags