Source Code Cross Referenced for CompressedFile.java in  » GIS » openjump » com » vividsolutions » jump » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » openjump » com.vividsolutions.jump.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CompressedFile.java
003:         *
004:         * Created on December 12, 2002, 9:51 AM
005:         */
006:        /*
007:         * The Unified Mapping Platform (JUMP) is an extensible, interactive
008:         * GUI for visualizing and manipulating spatial features with geometry
009:         * and attributes.
010:         *
011:         * Copyright (C) 2003 Vivid Solutions
012:         * 
013:         * This program is free software; you can redistribute it and/or
014:         * modify it under the terms of the GNU General Public License
015:         * as published by the Free Software Foundation; either version 2
016:         * of the License, or (at your option) any later version.
017:         * 
018:         * This program is distributed in the hope that it will be useful,
019:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
020:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021:         * GNU General Public License for more details.
022:         * 
023:         * You should have received a copy of the GNU General Public License
024:         * along with this program; if not, write to the Free Software
025:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
026:         * 
027:         * For more information, contact:
028:         *
029:         * Vivid Solutions
030:         * Suite #1A
031:         * 2328 Government Street
032:         * Victoria BC  V8T 5G5
033:         * Canada
034:         *
035:         * (250)385-6040
036:         * www.vividsolutions.com
037:         */
038:
039:        package com.vividsolutions.jump.io;
040:
041:        import java.io.FileInputStream;
042:        import java.io.InputStream;
043:        import java.util.zip.ZipEntry;
044:        import java.util.zip.ZipInputStream;
045:
046:        /**
047:         * Utility class for dealing with compressed (.zip, .gz) files.
048:         *
049:         * @author  dblasby
050:         * @TODO :I18N
051:         */
052:        public class CompressedFile {
053:
054:            /** Creates a new CompressedFile */
055:            public CompressedFile() {
056:            }
057:
058:            /**
059:             *   Searches through the .zip file looking for a file with the
060:             *   given extension.  Returns null if it doesn't find one.
061:             */
062:            public static String getInternalZipFnameByExtension(
063:                    String extension, String compressedFile) throws Exception {
064:                //zip file
065:                String inside_zip_extension;
066:                InputStream IS_low = new FileInputStream(compressedFile);
067:                ZipInputStream fr_high = new ZipInputStream(IS_low);
068:
069:                //need to find the correct file within the .zip file
070:                ZipEntry entry;
071:
072:                entry = fr_high.getNextEntry();
073:
074:                while (entry != null) {
075:                    inside_zip_extension = entry.getName().substring(
076:                            entry.getName().length() - extension.length());
077:
078:                    if (inside_zip_extension.compareToIgnoreCase(extension) == 0) {
079:                        return (entry.getName());
080:                    }
081:
082:                    entry = fr_high.getNextEntry();
083:                }
084:
085:                return null;
086:            }
087:
088:            /**
089:             *   Utility file open function - handles compressed and
090:             *   un-compressed files.
091:             *
092:             *  @param compressedFile name of file to open.
093:             *  @param extension look for file with this extension in zipfile.
094:             *
095:             *  <p>
096:             *  compressedFile = null, then opens a FileInputStream on
097:             *  COMPRESSEDFILE (!)  should be file.shp or such
098:             *  </p>
099:             *
100:             *  <p> 
101:             *  compressedFile ends in ".zip" - opens the compressed zipfile
102:             *  and lookes for first file with extension 'extension'
103:             *  </p> 
104:             *
105:             *  <p> 
106:             *  compressedFile ends in ".gz"  - opens the compressed .gz file.
107:             *  </p> 
108:             */
109:            static InputStream openFileExtension(String extension,
110:                    String compressedFile) throws Exception {
111:                String compressed_extension;
112:                String inside_zip_extension;
113:
114:                if ((compressedFile == null) || (compressedFile.length() == 0)) {
115:                    throw new Exception(
116:                            "openFileExtension- no compressed file given.");
117:                }
118:
119:                compressed_extension = compressedFile.substring(compressedFile
120:                        .length() - 3);
121:
122:                if (compressed_extension.compareToIgnoreCase(".gz") == 0) {
123:                    // gz file -- easy
124:
125:                    // low-level reader
126:                    InputStream IS_low = new FileInputStream(compressedFile);
127:
128:                    // high-level reader
129:                    return (new java.util.zip.GZIPInputStream(IS_low));
130:                }
131:
132:                if (compressed_extension.compareToIgnoreCase("zip") == 0) {
133:                    //zip file
134:                    InputStream IS_low = new FileInputStream(compressedFile);
135:                    ZipInputStream fr_high = new ZipInputStream(IS_low);
136:
137:                    //need to find the correct file within the .zip file
138:                    ZipEntry entry;
139:
140:                    entry = fr_high.getNextEntry();
141:
142:                    while (entry != null) {
143:                        inside_zip_extension = entry.getName().substring(
144:                                entry.getName().length() - extension.length());
145:
146:                        if (inside_zip_extension.compareToIgnoreCase(extension) == 0) {
147:                            return (fr_high);
148:                        }
149:
150:                        entry = fr_high.getNextEntry();
151:                    }
152:
153:                    throw new Exception("couldnt find file with extension"
154:                            + extension + " in compressed file "
155:                            + compressedFile);
156:                }
157:
158:                throw new Exception(
159:                        "couldnt determine compressed file type for file "
160:                                + compressedFile
161:                                + "- should end in .zip or .gz");
162:            }
163:
164:            /**
165:             * Utility file open function - handles compressed and un-compressed files.
166:             *
167:             * @param fname name of the file to search for.
168:             * @param compressedFile name of the compressed file.
169:             *
170:             *  <p>
171:             *  If compressedFile = null,  opens a FileInputStream on fname
172:             *  </p>
173:             *
174:             *  <p>
175:             *  compressedFile ends in ".zip" - opens the compressed Zip and
176:             *  lookes for the file called fname
177:             *  </p>     
178:             *
179:             *  <p>
180:             *  compressedFile ends in ".gz"  - opens the compressed .gz file.
181:             *  </p>
182:             */
183:            static InputStream openFile(String fname, String compressedFile)
184:                    throws Exception {
185:                String extension;
186:
187:                if ((compressedFile == null) || (compressedFile.length() == 0)) {
188:                    return new FileInputStream(fname);
189:                }
190:
191:                extension = compressedFile
192:                        .substring(compressedFile.length() - 3);
193:
194:                if (extension.compareToIgnoreCase(".gz") == 0) {
195:                    // gz file -- easy
196:
197:                    // low-level reader
198:                    InputStream IS_low = new FileInputStream(compressedFile);
199:
200:                    // high-level reader
201:                    return (new java.util.zip.GZIPInputStream(IS_low));
202:                }
203:
204:                if (extension.compareToIgnoreCase("zip") == 0) {
205:                    //zip file
206:                    InputStream IS_low = new FileInputStream(compressedFile);
207:                    ZipInputStream fr_high = new ZipInputStream(IS_low);
208:
209:                    //need to find the correct file within the .zip file
210:                    ZipEntry entry;
211:
212:                    entry = fr_high.getNextEntry();
213:
214:                    while (entry != null) {
215:                        if (entry.getName().compareToIgnoreCase(fname) == 0) {
216:                            return (fr_high);
217:                        }
218:
219:                        entry = fr_high.getNextEntry();
220:                    }
221:
222:                    throw new Exception("couldnt find " + fname
223:                            + " in compressed file " + compressedFile);
224:                }
225:
226:                throw new Exception(
227:                        "Couldn't determine compressed file type for file "
228:                                + compressedFile
229:                                + " - Should end in .zip or .gz");
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.