Source code: com/lutris/classloader/LocalZipResource.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific terms governing rights and limitations
12 * under the License.
13 *
14 * The Initial Developer of the Enhydra Application Server is Lutris
15 * Technologies, Inc. The Enhydra Application Server and portions created
16 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17 * All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * $Id: LocalZipResource.java,v 1.15.2.1.2.1 2000/10/19 17:58:53 jasona Exp $
22 */
23
24
25
26
27
28 package com.lutris.classloader;
29
30 // lutris packages
31 import com.lutris.logging.LogChannel;
32 import com.lutris.util.FatalExceptionError;
33
34 // io packages
35 import java.io.InputStream;
36
37 // io exceptions
38 import java.io.IOException;
39 import java.io.FileNotFoundException;
40
41 // zip packages
42 import java.util.zip.ZipFile;
43 import java.util.zip.ZipEntry;
44
45 /**
46 * <P>A <CODE>Resource</CODE> that is an entry in
47 * a specified zip file on the local machine. The zip file is represented by a
48 * <CODE>ClassPathEntry</CODE>, and the filename is specified by a String.
49 *
50 * @author Kristen Pol, Lutris Technologies
51 * @version $Revision : 1.1 $
52 * @see com.lutris.classloader.ClassPathEntry
53 * @see com.lutris.classloader.Resource
54 * @see java.util.zip.ZipFile
55 * @see java.util.zip.ZipEntry
56 */
57 public class LocalZipResource extends Resource {
58
59 // private data members
60
61 /** The ZipEntry that represents this resource. */
62 private ZipEntry zipEntry = null;
63
64 // constructors
65
66 /**
67 * Constructs local zip file resource with specified name and location.
68 *
69 * @param name The file name of the resource.
70 * @param location The location of the resource.
71 * @param loadLogChannel The log channel for logging.
72 * @exception FileNotFoundException if the desired file does not exist or
73 * does not have read permission.
74 * @see Resource
75 * @see ClassPathEntry
76 */
77 protected LocalZipResource(String name, ClassPathEntry location,
78 LogChannel loadLogChannel)
79 throws FileNotFoundException {
80 super(name, location, loadLogChannel);
81 ZipFile zipFile = location.getZipFile();
82 if (zipFile == null) {
83 throw new FileNotFoundException( "There is no zip file associated with resource: "
84 + location);
85 }
86 try {
87 zipEntry = zipFile.getEntry(name);
88 if (zipEntry == null) {
89 throw new FileNotFoundException("Entry, " + name
90 + ", does not exist in zip "
91 + "file, " + zipFile);
92 }
93 size = zipEntry.getSize();
94 //lastModifiedTime = zipEntry.getTime();
95 } catch (IOException e) {
96 throw new FileNotFoundException("Entry, " + name
97 + ", does not exist in zip file, "
98 + zipFile + ", or is " + "corrupt: "
99 + e.getMessage());
100 }
101 }
102
103 // public methods
104
105 /**
106 * Gets input stream representing resource.
107 *
108 * @return the input stream that represents the resource.
109 * @exception IOException if the input stream can not be constructed.
110 * @see InputStream
111 */
112 public InputStream getInputStream() throws IOException {
113 ZipFile zipFile = location.getZipFile();
114 if (zipFile == null) {
115 throw new FatalExceptionError(new IOException("Failed to get zip file for location, should not be able to get here without a zip file"));
116 }
117 return zipFile.getInputStream(zipEntry);
118 }
119
120 /**
121 * Get current last-modification time of resource. This is the
122 * time on the disk file the resource is associated with.
123 *
124 * @return the last-modified time of the permanent copy of the resource
125 * in milliseconds.
126 */
127 public long getCurrentLastModifiedTime() throws FileNotFoundException {
128 lastModifiedTime = zipEntry.getTime();
129 return lastModifiedTime;
130 //return zipEntry.getTime();
131 }
132 }