Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / ZipFileFolder.java @ 6

History | View | Annotate | Download (1.83 KB)

1
/*
2
 * Created on 03-may-2004
3
 *
4
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
5
 */
6
package org.cresques.io;
7

    
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.util.Enumeration;
11
import java.util.zip.ZipEntry;
12
import java.util.zip.ZipFile;
13

    
14
/**
15
 *
16
 *  
17
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
18
 */
19

    
20
public class ZipFileFolder extends FileFolder {
21
        String zName = null;
22
        public ZipFile file = null;
23
        
24
        public ZipFileFolder() {
25
                super();
26
        }
27
        
28
        /**
29
         * Constructor.
30
         * 
31
         * @param fname
32
         */
33
        
34
        public ZipFileFolder(String fName) throws IOException {
35
                if (isUrl(fName))
36
                        zName = getZName(fName);
37
                else
38
                        zName = fName;
39
                if (fName.substring(0) == "[") {
40
                        DataSource ds = DataSource.getDSFromName(fName);
41
                        fName = ds.getPath() + fName.substring(fName.indexOf("]")+1);
42
                        System.out.println(fName);
43
                }
44
                file = new ZipFile(zName);
45
        }
46
        
47
        /**
48
         * Analiza un nombre de fichero en formato zip://zipname.zip?file.ext
49
         * @param urlName
50
         */
51
        
52
        public static boolean isUrl(String name) {
53
                String str = name.substring(0,3);
54
                str.toLowerCase();
55
                if (str.compareTo("zip") == 0)
56
                        return true;
57
                return false;
58
        }
59
        
60
        private String getZName(String urlName) {
61
                return urlName.substring(6,urlName.indexOf("?"));
62
        }
63
        private String getFName(String urlName) {
64
                return urlName.substring(urlName.indexOf("?")+1);
65
        }
66
        
67
        public ZipEntry getZipEntry(String fName) throws IOException {
68
                InputStream is = null;
69
                if (isUrl(fName))
70
                        fName = getFName(fName);
71
                return file.getEntry(fName);
72
        }
73
        
74
        public InputStream getInputStream(String fName) throws IOException {
75
                return file.getInputStream(getZipEntry(fName));
76
        }
77
        
78
        public InputStream getInputStream(ZipEntry ze) throws IOException {
79
                return file.getInputStream(ze);
80
        }
81
        
82
        public int count() { return file.size(); }
83
        
84
        public Enumeration entries() { return file.entries();}
85
}