KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > classloader > LocalZipResource


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: LocalZipResource.java,v 1.2 2005/03/24 10:51:25 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.classloader;
30
31 // lutris packages
32
// v. strahinja, 24 sep 2002
33
import java.io.FileNotFoundException JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.InputStream JavaDoc;
36 import java.util.zip.ZipEntry JavaDoc;
37 import java.util.zip.ZipFile JavaDoc;
38
39 import com.lutris.logging.LogChannel;
40 import com.lutris.util.FatalExceptionError;
41
42 /**
43  * <P>A <CODE>Resource</CODE> that is an entry in
44  * a specified zip file on the local machine. The zip file is represented by a
45  * <CODE>ClassPathEntry</CODE>, and the filename is specified by a String.
46  *
47  * @author Kristen Pol, Lutris Technologies
48  * @version $Revision : 1.1 $
49  * @see com.lutris.classloader.ClassPathEntry
50  * @see com.lutris.classloader.Resource
51  * @see java.util.zip.ZipFile
52  * @see java.util.zip.ZipEntry
53  */

54 public class LocalZipResource extends Resource {
55
56     // private data members
57

58     /** The ZipEntry that represents this resource. */
59     private ZipEntry JavaDoc zipEntry = null;
60
61     // constructors
62

63     /**
64      * Constructs local zip file resource with specified name and location.
65      *
66      * @param name The file name of the resource.
67      * @param location The location of the resource.
68      * @param loadLogChannel The log channel for logging.
69      * @exception FileNotFoundException if the desired file does not exist or
70      * does not have read permission.
71      * @see Resource
72      * @see ClassPathEntry
73      */

74     protected LocalZipResource(String JavaDoc name, ClassPathEntry location,
75 // v. strahinja, 24 sep 2002
76
LogChannel loadLogChannel)
77 // Logger loadLogger)
78
throws FileNotFoundException JavaDoc {
79 // v. strahinja, 24 sep 2002
80
super(name, location, loadLogChannel);
81 // super(name, location, loadLogger);
82
ZipFile JavaDoc zipFile = location.getZipFile();
83     if (zipFile == null) {
84         throw new FileNotFoundException JavaDoc( "There is no zip file associated with resource: "
85                                              + location);
86     }
87     try {
88         zipEntry = zipFile.getEntry(name);
89         if (zipEntry == null) {
90         throw new FileNotFoundException JavaDoc("Entry, " + name
91                                                 + ", does not exist in zip "
92                                                 + "file, " + zipFile);
93         }
94         size = zipEntry.getSize();
95         //lastModifiedTime = zipEntry.getTime();
96
} catch (IOException JavaDoc e) {
97         throw new FileNotFoundException JavaDoc("Entry, " + name
98                                             + ", does not exist in zip file, "
99                                             + zipFile + ", or is " + "corrupt: "
100                                             + e.getMessage());
101     }
102     }
103
104     // public methods
105

106     /**
107      * Gets input stream representing resource.
108      *
109      * @return the input stream that represents the resource.
110      * @exception IOException if the input stream can not be constructed.
111      * @see InputStream
112      */

113     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
114     ZipFile JavaDoc zipFile = location.getZipFile();
115     if (zipFile == null) {
116             throw new FatalExceptionError(new IOException JavaDoc("Failed to get zip file for location, should not be able to get here without a zip file"));
117         }
118         return zipFile.getInputStream(zipEntry);
119     }
120
121     /**
122      * Get current last-modification time of resource. This is the
123      * time on the disk file the resource is associated with.
124      *
125      * @return the last-modified time of the permanent copy of the resource
126      * in milliseconds.
127      */

128     public long getCurrentLastModifiedTime() throws FileNotFoundException JavaDoc {
129     lastModifiedTime = zipEntry.getTime();
130         return lastModifiedTime;
131         //return zipEntry.getTime();
132
}
133 }
134
Popular Tags