root / tags / v1_1_Build_914 / libraries / libCq CMS for java.old / src / org / cresques / io / ZipFileFolder.java @ 11873
History | View | Annotate | Download (2.75 KB)
1 | 2 | luisw | /*
|
---|---|---|---|
2 | 2809 | nacho | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 | 2 | luisw | *
|
4 | 2809 | nacho | * 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 | 2 | luisw | */
|
24 | package org.cresques.io; |
||
25 | |||
26 | import java.io.IOException; |
||
27 | import java.io.InputStream; |
||
28 | 2809 | nacho | |
29 | 2 | luisw | import java.util.Enumeration; |
30 | import java.util.zip.ZipEntry; |
||
31 | import java.util.zip.ZipFile; |
||
32 | |||
33 | 2809 | nacho | |
34 | 2 | luisw | /**
|
35 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
||
36 | */
|
||
37 | 2809 | nacho | public class ZipFileFolder extends FileFolder { |
38 | String zName = null; |
||
39 | public ZipFile file = null; |
||
40 | 2 | luisw | |
41 | 2809 | nacho | 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 | } |
||
110 | 2 | luisw | } |