001: package com.quadcap.io.dir;
002:
003: /* Copyright 2000 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.File;
042: import java.io.IOException;
043:
044: import java.util.Enumeration;
045:
046: import java.util.jar.JarFile;
047:
048: import java.net.MalformedURLException;
049: import java.net.URL;
050:
051: /**
052: *
053: *
054: * @author Stan Bailes
055: */
056:
057: public class JarDirectory extends Directory {
058: URL base;
059: JarFile jar;
060: File file;
061:
062: public JarDirectory(File f) throws IOException {
063: this .file = f;
064: this .jar = new JarFile(f);
065: this .base = new URL("jar:file:" + f.getAbsolutePath() + "!/");
066: }
067:
068: public Enumeration entries() {
069: final JarDirectory dir = this ;
070: final Enumeration je = jar.entries();
071: return new Enumeration() {
072: public boolean hasMoreElements() {
073: return je.hasMoreElements();
074: }
075:
076: public Object nextElement() {
077: java.util.jar.JarEntry j = (java.util.jar.JarEntry) je
078: .nextElement();
079: return j.getName();
080: }
081: };
082: }
083:
084: public Entry getEntry(String name) {
085: java.util.jar.JarEntry j = jar.getJarEntry(name);
086: if (j != null) {
087: return new JarEntry(this , j);
088: } else {
089: return null;
090: }
091: }
092:
093: public URL getURL(String name) throws MalformedURLException {
094: URL url = null;
095: if (name.charAt(0) == '/')
096: name = name.substring(1);
097: java.util.jar.JarEntry j = jar.getJarEntry(name);
098: if (j != null) {
099: url = new URL(base, name);
100: }
101: return url;
102: }
103:
104: public String getRealPath(String name) {
105: return null;
106: }
107:
108: public String getRootPath() {
109: return file.getAbsolutePath();
110: }
111:
112: public void close() throws IOException {
113: jar.close();
114: }
115:
116: public boolean isFile() {
117: return false;
118: }
119: }
|