[Schmitzm-commits] r1507 - trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/io
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Mar 5 20:03:48 CET 2011
Author: alfonx
Date: 2011-03-05 20:03:47 +0100 (Sat, 05 Mar 2011)
New Revision: 1507
Modified:
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/io/GeoImportUtil.java
Log:
Shapes in ZIPs are now correctly imported even if the SHP is in a sub directory
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/io/GeoImportUtil.java 2011-03-05 19:03:14 UTC (rev 1506)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/io/GeoImportUtil.java 2011-03-05 19:03:47 UTC (rev 1507)
@@ -101,7 +101,7 @@
* @author Stefan Tzeggai, wikisquare.de
*/
public class GeoImportUtil {
-
+
/**
* This type specifies how this class can proceed the import of ASCII
* rasters.
@@ -804,8 +804,8 @@
try {
return readGridFromGeoTiff(file, null);
} catch (DataSourceException dse) {
- LOGGER.warn("Failed trying to import " + file + " with RasterReader",
- dse);
+ LOGGER.warn("Failed trying to import " + file
+ + " with RasterReader", dse);
return readGridFromGeoTiff(file, getDefaultCRS());
}
}
@@ -1533,9 +1533,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)
@@ -1558,15 +1560,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