Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / io / ZipFileFolder.java @ 21930

History | View | Annotate | Download (2.85 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.util.Enumeration;
29
import java.util.zip.ZipEntry;
30
import java.util.zip.ZipFile;
31

    
32

    
33
/**
34
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
35
 */
36
public class ZipFileFolder extends FileFolder {
37
    String zName = null;
38
    public ZipFile file = null;
39

    
40
    public ZipFileFolder() {
41
        super();
42
    }
43

    
44
    /**
45
     * Constructor.
46
     *
47
     * @param fname
48
     */
49
    public ZipFileFolder(String fName) throws IOException {
50
        fName = DataSource.normalize(fName);
51

    
52
        if (isUrl(fName)) {
53
            zName = getZName(fName);
54
        } else {
55
            zName = fName;
56
        }
57

    
58
        file = new ZipFile(zName);
59
    }
60

    
61
    /**
62
     * Analiza un nombre de fichero en formato zip://zipname.zip?file.ext
63
     * @param urlName
64
     */
65
    public static boolean isUrl(String name) {
66
        String str = name.substring(0, 3);
67
        str.toLowerCase();
68

    
69
        if (str.compareTo("zip") == 0) {
70
            return true;
71
        }
72

    
73
        return false;
74
    }
75

    
76
    private String getZName(String urlName) {
77
        return urlName.substring(6, urlName.indexOf("?"));
78
    }
79

    
80
    private String getFName(String urlName) {
81
        return urlName.substring(urlName.indexOf("?") + 1);
82
    }
83

    
84
    public ZipEntry getZipEntry(String fName) throws IOException {
85
        InputStream is = null;
86

    
87
        if (isUrl(fName)) {
88
            fName = getFName(fName);
89
        }
90

    
91
        return file.getEntry(fName);
92
    }
93

    
94
    public InputStream getInputStream(String fName) throws IOException {
95
        return file.getInputStream(getZipEntry(fName));
96
    }
97

    
98
    public InputStream getInputStream(ZipEntry ze) throws IOException {
99
        return file.getInputStream(ze);
100
    }
101

    
102
    public int count() {
103
        return file.size();
104
    }
105

    
106
    public Enumeration entries() {
107
        return file.entries();
108
    }
109
}