[Schmitzm-commits] r1506 - branches/2.3.x/src/schmitzm/geotools/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Mar 5 20:03:15 CET 2011


Author: alfonx
Date: 2011-03-05 20:03:14 +0100 (Sat, 05 Mar 2011)
New Revision: 1506

Modified:
   branches/2.3.x/src/schmitzm/geotools/io/GeoImportUtil.java
Log:
Shapes in ZIPs are now correctly imported even if the SHP is in a sub directory

Modified: branches/2.3.x/src/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- branches/2.3.x/src/schmitzm/geotools/io/GeoImportUtil.java	2011-03-05 10:42:50 UTC (rev 1505)
+++ branches/2.3.x/src/schmitzm/geotools/io/GeoImportUtil.java	2011-03-05 19:03:14 UTC (rev 1506)
@@ -1527,9 +1527,11 @@
 
 	/**
 	 * Entpackt einen ZIP Stream nach tmp und liefert eine URL auf die erste
-	 * gefundene .SHP Datei zurück. TODO Die entpackten Dateien bleiben in Temp
-	 * liegen!.
+	 * gefundene .SHP Datei zurück. Die Shape darf also auch in einem
+	 * Unterverzeichnis liegen!
 	 * 
+	 * TODO Die entpackten Dateien bleiben in Temp liegen!.
+	 * 
 	 * @throws IOException
 	 */
 	public static URL uncompressShapeZip(InputStream zippedInputstream)
@@ -1552,15 +1554,24 @@
 			while ((entry = inStream.getNextEntry()) != null) {
 
 				File targetFile = new File(tempFolder, entry.getName());
-				targetFile.getParentFile().mkdirs();
-				OutputStream outStream = new FileOutputStream(targetFile);
-				while ((nrBytesRead = inStream.read(buffer)) > 0) {
-					outStream.write(buffer, 0, nrBytesRead);
+				if (entry.isDirectory())
+					targetFile.mkdirs();
+				else {
+					targetFile.getParentFile().mkdirs();
+					OutputStream outStream = new FileOutputStream(targetFile);
+					try {
+
+						while ((nrBytesRead = inStream.read(buffer)) > 0) {
+							outStream.write(buffer, 0, nrBytesRead);
+						}
+						if (entry.getName().toLowerCase().endsWith(".shp")) {
+							shpUrl = DataUtilities.fileToURL(targetFile);
+						}
+					} finally {
+						if (outStream != null)
+							outStream.close();
+					}
 				}
-				if (entry.getName().toLowerCase().endsWith(".shp")) {
-					shpUrl = DataUtilities.fileToURL(targetFile);
-				}
-				outStream.close();
 			}
 
 		} finally {



More information about the Schmitzm-commits mailing list