svn-gvsig-desktop / tags / Root_CqCMSGisPlanet / libraries / libCq CMS for java.old / src / org / cresques / io / ZipFileFolder.java @ 1933
History | View | Annotate | Download (1.69 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 |
fName = DataSource.normalize(fName);
|
36 |
if (isUrl(fName))
|
37 |
zName = getZName(fName); |
38 |
else
|
39 |
zName = fName; |
40 |
file = new ZipFile(zName); |
41 |
} |
42 |
|
43 |
/**
|
44 |
* Analiza un nombre de fichero en formato zip://zipname.zip?file.ext
|
45 |
* @param urlName
|
46 |
*/
|
47 |
|
48 |
public static boolean isUrl(String name) { |
49 |
String str = name.substring(0,3); |
50 |
str.toLowerCase(); |
51 |
if (str.compareTo("zip") == 0) |
52 |
return true; |
53 |
return false; |
54 |
} |
55 |
|
56 |
private String getZName(String urlName) { |
57 |
return urlName.substring(6,urlName.indexOf("?")); |
58 |
} |
59 |
private String getFName(String urlName) { |
60 |
return urlName.substring(urlName.indexOf("?")+1); |
61 |
} |
62 |
|
63 |
public ZipEntry getZipEntry(String fName) throws IOException { |
64 |
InputStream is = null; |
65 |
if (isUrl(fName))
|
66 |
fName = getFName(fName); |
67 |
return file.getEntry(fName);
|
68 |
} |
69 |
|
70 |
public InputStream getInputStream(String fName) throws IOException { |
71 |
return file.getInputStream(getZipEntry(fName));
|
72 |
} |
73 |
|
74 |
public InputStream getInputStream(ZipEntry ze) throws IOException { |
75 |
return file.getInputStream(ze);
|
76 |
} |
77 |
|
78 |
public int count() { return file.size(); } |
79 |
|
80 |
public Enumeration entries() { return file.entries();} |
81 |
} |