KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17
18 /**
19  * A BundleEntry represented by a File object. The FileBundleEntry class is
20  * used for bundles that are installed as extracted zips on a file system.
21  * @since 3.2
22  */

23 public class FileBundleEntry extends BundleEntry {
24     /**
25      * File for this entry.
26      */

27     private File file;
28     /**
29      * The name for this entry
30      */

31     String JavaDoc name;
32
33     /**
34      * Constructs the BundleEntry using a File.
35      * @param file BundleFile object this entry is a member of
36      * @param name the name of this BundleEntry
37      */

38     FileBundleEntry(File file, String JavaDoc name) {
39         this.file = file;
40         this.name = name;
41     }
42
43     /**
44      * Return an InputStream for the entry.
45      *
46      * @return InputStream for the entry
47      * @exception java.io.IOException
48      */

49     public InputStream getInputStream() throws IOException {
50         return BundleFile.secureAction.getFileInputStream(file);
51     }
52
53     /**
54      * Return size of the uncompressed entry.
55      *
56      * @return size of entry
57      */

58     public long getSize() {
59         return BundleFile.secureAction.length(file);
60     }
61
62     /**
63      * Return name of the entry.
64      *
65      * @return name of entry
66      */

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

78     public long getTime() {
79         return BundleFile.secureAction.lastModified(file);
80     }
81
82     public URL JavaDoc getLocalURL() {
83         return getFileURL();
84     }
85
86     public URL JavaDoc getFileURL() {
87         try {
88             return file.toURL();
89         } catch (MalformedURLException JavaDoc e) {
90             return null;
91         }
92     }
93 }
94
Popular Tags