KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 package org.eclipse.osgi.baseadaptor.bundlefile;
13
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.net.MalformedURLException JavaDoc;
17 import java.net.URL JavaDoc;
18
19 /**
20  * Represents a directory entry in a ZipBundleFile. This object is used to
21  * reference a directory entry in a ZipBundleFile when the directory entries are
22  * not included in the zip file.
23  * @since 3.2
24  */

25 public class DirZipBundleEntry extends BundleEntry {
26
27     /**
28      * ZipBundleFile for this entry.
29      */

30     private ZipBundleFile bundleFile;
31     /**
32      * The name for this entry
33      */

34     String JavaDoc name;
35
36     public DirZipBundleEntry(ZipBundleFile bundleFile, String JavaDoc name) {
37         this.name = (name.length() > 0 && name.charAt(0) == '/') ? name.substring(1) : name;
38         this.bundleFile = bundleFile;
39     }
40
41     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
42         return null;
43     }
44
45     public long getSize() {
46         return 0;
47     }
48
49     public String JavaDoc getName() {
50         return name;
51     }
52
53     public long getTime() {
54         return 0;
55     }
56
57     public URL JavaDoc getLocalURL() {
58         try {
59             return new URL JavaDoc("jar:file:" + bundleFile.basefile.getAbsolutePath() + "!/" + name); //$NON-NLS-1$ //$NON-NLS-2$
60
} catch (MalformedURLException JavaDoc e) {
61             //This can not happen, unless the jar protocol is not supported.
62
return null;
63         }
64     }
65
66     public URL JavaDoc getFileURL() {
67         try {
68             return bundleFile.extractDirectory(name).toURL();
69         } catch (MalformedURLException JavaDoc e) {
70             // this cannot happen.
71
return null;
72         }
73     }
74 }
75
Popular Tags