Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/ZipFileFolder.java
ZipFileFolder.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io; |
25 | 25 |
|
26 | 26 |
import java.io.IOException; |
27 | 27 |
import java.io.InputStream; |
28 |
|
|
28 | 29 |
import java.util.Enumeration; |
29 | 30 |
import java.util.zip.ZipEntry; |
30 | 31 |
import java.util.zip.ZipFile; |
31 | 32 |
|
33 |
|
|
32 | 34 |
/** |
33 | 35 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
34 | 36 |
*/ |
37 |
public class ZipFileFolder extends FileFolder { |
|
38 |
String zName = null; |
|
39 |
public ZipFile file = null; |
|
35 | 40 |
|
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 |
|
|
50 |
public ZipFileFolder(String fName) throws IOException { |
|
51 |
fName = DataSource.normalize(fName); |
|
52 |
if (isUrl(fName)) |
|
53 |
zName = getZName(fName); |
|
54 |
else |
|
55 |
zName = fName; |
|
56 |
file = new ZipFile(zName); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Analiza un nombre de fichero en formato zip://zipname.zip?file.ext |
|
61 |
* @param urlName |
|
62 |
*/ |
|
63 |
|
|
64 |
public static boolean isUrl(String name) { |
|
65 |
String str = name.substring(0,3); |
|
66 |
str.toLowerCase(); |
|
67 |
if (str.compareTo("zip") == 0) |
|
68 |
return true; |
|
69 |
return false; |
|
70 |
} |
|
71 |
|
|
72 |
private String getZName(String urlName) { |
|
73 |
return urlName.substring(6,urlName.indexOf("?")); |
|
74 |
} |
|
75 |
private String getFName(String urlName) { |
|
76 |
return urlName.substring(urlName.indexOf("?")+1); |
|
77 |
} |
|
78 |
|
|
79 |
public ZipEntry getZipEntry(String fName) throws IOException { |
|
80 |
InputStream is = null; |
|
81 |
if (isUrl(fName)) |
|
82 |
fName = getFName(fName); |
|
83 |
return file.getEntry(fName); |
|
84 |
} |
|
85 |
|
|
86 |
public InputStream getInputStream(String fName) throws IOException { |
|
87 |
return file.getInputStream(getZipEntry(fName)); |
|
88 |
} |
|
89 |
|
|
90 |
public InputStream getInputStream(ZipEntry ze) throws IOException { |
|
91 |
return file.getInputStream(ze); |
|
92 |
} |
|
93 |
|
|
94 |
public int count() { return file.size(); } |
|
95 |
|
|
96 |
public Enumeration entries() { return file.entries();} |
|
41 |
public ZipFileFolder() { |
|
42 |
super(); |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Constructor. |
|
47 |
* |
|
48 |
* @param fname |
|
49 |
*/ |
|
50 |
public ZipFileFolder(String fName) throws IOException { |
|
51 |
fName = DataSource.normalize(fName); |
|
52 |
|
|
53 |
if (isUrl(fName)) { |
|
54 |
zName = getZName(fName); |
|
55 |
} else { |
|
56 |
zName = fName; |
|
57 |
} |
|
58 |
|
|
59 |
file = new ZipFile(zName); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Analiza un nombre de fichero en formato zip://zipname.zip?file.ext |
|
64 |
* @param urlName |
|
65 |
*/ |
|
66 |
public static boolean isUrl(String name) { |
|
67 |
String str = name.substring(0, 3); |
|
68 |
str.toLowerCase(); |
|
69 |
|
|
70 |
if (str.compareTo("zip") == 0) { |
|
71 |
return true; |
|
72 |
} |
|
73 |
|
|
74 |
return false; |
|
75 |
} |
|
76 |
|
|
77 |
private String getZName(String urlName) { |
|
78 |
return urlName.substring(6, urlName.indexOf("?")); |
|
79 |
} |
|
80 |
|
|
81 |
private String getFName(String urlName) { |
|
82 |
return urlName.substring(urlName.indexOf("?") + 1); |
|
83 |
} |
|
84 |
|
|
85 |
public ZipEntry getZipEntry(String fName) throws IOException { |
|
86 |
InputStream is = null; |
|
87 |
|
|
88 |
if (isUrl(fName)) { |
|
89 |
fName = getFName(fName); |
|
90 |
} |
|
91 |
|
|
92 |
return file.getEntry(fName); |
|
93 |
} |
|
94 |
|
|
95 |
public InputStream getInputStream(String fName) throws IOException { |
|
96 |
return file.getInputStream(getZipEntry(fName)); |
|
97 |
} |
|
98 |
|
|
99 |
public InputStream getInputStream(ZipEntry ze) throws IOException { |
|
100 |
return file.getInputStream(ze); |
|
101 |
} |
|
102 |
|
|
103 |
public int count() { |
|
104 |
return file.size(); |
|
105 |
} |
|
106 |
|
|
107 |
public Enumeration entries() { |
|
108 |
return file.entries(); |
|
109 |
} |
|
97 | 110 |
} |
Also available in: Unified diff