Changeset 29938 in osm for applications


Ignore:
Timestamp:
2013-09-20T22:15:29+02:00 (11 years ago)
Author:
donvip
Message:

[josm_opendata] fix #josm9088 - support KMZ files containing other files than KML doc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmzReader.java

    r28000 r29938  
    1717
    1818import java.io.ByteArrayInputStream;
     19import java.io.ByteArrayOutputStream;
    1920import java.io.IOException;
    2021import java.io.InputStream;
     22import java.util.zip.ZipEntry;
    2123import java.util.zip.ZipInputStream;
    2224
     
    2426import javax.xml.stream.XMLStreamException;
    2527
     28import org.openstreetmap.josm.Main;
    2629import org.openstreetmap.josm.data.osm.DataSet;
    2730import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    4245
    4346        private DataSet parseDoc(ProgressMonitor instance) throws IOException, XMLStreamException, FactoryConfigurationError  {
    44                 long size = zis.getNextEntry().getSize();
    45                 byte[] buffer = new byte[(int) size];
    46                 int off = 0;
    47                 int count = 0;
    48                 while ((count = zis.read(buffer, off, (int)size)) > 0) {
    49                         off += count;
    50                         size -= count;
    51                 }
     47            ZipEntry entry;
     48            do {
     49                entry = zis.getNextEntry();
     50                if (entry == null) {
     51                    Main.warn("No KML file found");
     52                    return null;
     53                }
     54            } while (!entry.getName().toLowerCase().endsWith(".kml"));
     55                long size = entry.getSize();
     56                byte[] buffer;
     57                if (size > 0) {
     58            buffer = new byte[(int) size];
     59            int off = 0;
     60            int count = 0;
     61            while ((count = zis.read(buffer, off, (int) size)) > 0) {
     62                off += count;
     63                size -= count;
     64            }
     65        } else {
     66            ByteArrayOutputStream out = new ByteArrayOutputStream();
     67            int b;
     68            do {
     69                b = zis.read();
     70                if (b != -1) {
     71                    out.write(b);
     72                }
     73            } while (b != -1);
     74            buffer = out.toByteArray();
     75        }
     76           
    5277                return KmlReader.parseDataSet(new ByteArrayInputStream(buffer), instance);
    5378        }
Note: See TracChangeset for help on using the changeset viewer.