KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jarg > DirectoryHandler


1 /* ====================================================================
2  * Copyright (c) 2002, Hidetoshi Ohuchi <hchacha@users.sourceforge.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the hchacha nor the names of its contributors
17  * may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  * ====================================================================
33  */

34 package jarg;
35
36 import java.lang.Comparable JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.TreeMap JavaDoc;
39 import java.util.jar.JarFile JavaDoc;
40 import java.util.zip.ZipEntry JavaDoc;
41 import java.util.Comparator JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.Arrays JavaDoc;
45
46 /**
47  * The class for handling the directory entry in the jar file.
48  *
49  * @version $Id: DirectoryHandler.java,v 1.1 2002/03/12 15:11:26 hchacha Exp $
50  * @author Hidetoshi Ohuchi &lt;hchacha@users.sourceforge.net&gt;
51  */

52 class DirectoryHandler implements Comparable JavaDoc {
53    private Jarg app;
54    String JavaDoc path;
55    private JarFile JavaDoc jarin;
56
57    private List JavaDoc lst = new ArrayList JavaDoc();
58    ZipEntry JavaDoc[] zes;
59
60    DirectoryHandler(Jarg app, String JavaDoc path, JarFile JavaDoc jarin) {
61       this.app = app;
62       this.path = path;
63       this.jarin = jarin;
64    }
65
66    void addFile(ZipEntry JavaDoc ze) {
67       lst.add(ze);
68    }
69
70    void fixEntry() {
71       zes = new ZipEntry JavaDoc[lst.size()];
72       lst.toArray(zes);
73       lst = null;
74
75       Arrays.sort(zes, new Comparator JavaDoc() {
76          public int compare(Object JavaDoc o1, Object JavaDoc o2) {
77             ZipEntry JavaDoc ze1 = (ZipEntry JavaDoc)o1;
78             ZipEntry JavaDoc ze2 = (ZipEntry JavaDoc)o2;
79             return ze1.getName().compareToIgnoreCase(ze2.getName());
80          }
81       });
82    }
83
84    public int compareTo(Object JavaDoc o1) {
85       DirectoryHandler a = (DirectoryHandler)o1;
86       return this.path.compareToIgnoreCase(a.path);
87    }
88 }
89
Popular Tags