Search in sources :

Example 1 with CompressionActivator

use of org.openstreetmap.osmosis.xml.common.CompressionActivator in project GeoGig by boundlessgeo.

the class XmlReader method run.

/**
     * Reads all data from the file and send it to the sink.
     */
public void run() {
    InputStream inputStream = this.file;
    try {
        SAXParser parser;
        sink.initialize(Collections.<String, Object>emptyMap());
        // make "-" an alias for /dev/stdin
        // if (file.getName().equals("-")) {
        // inputStream = System.in;
        // } else {
        // inputStream = new FileInputStream(file);
        // }
        inputStream = new CompressionActivator(compressionMethod).createCompressionInputStream(inputStream);
        parser = createParser();
        parser.parse(inputStream, new OsmHandler(sink, enableDateParsing));
        sink.complete();
    } catch (SAXParseException e) {
        throw new OsmosisRuntimeException("Unable to parse xml file " + file + ".  publicId=(" + e.getPublicId() + "), systemId=(" + e.getSystemId() + "), lineNumber=" + e.getLineNumber() + ", columnNumber=" + e.getColumnNumber() + ".", e);
    } catch (SAXException e) {
        throw new OsmosisRuntimeException("Unable to parse XML.", e);
    } catch (IOException e) {
        throw new OsmosisRuntimeException("Unable to read XML file " + file + ".", e);
    } finally {
        sink.release();
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                log.log(Level.SEVERE, "Unable to close input stream.", e);
            }
            inputStream = null;
        }
    }
}
Also used : InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) SAXParser(javax.xml.parsers.SAXParser) OsmHandler(org.openstreetmap.osmosis.xml.v0_6.impl.OsmHandler) IOException(java.io.IOException) CompressionActivator(org.openstreetmap.osmosis.xml.common.CompressionActivator) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SAXParser (javax.xml.parsers.SAXParser)1 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)1 CompressionActivator (org.openstreetmap.osmosis.xml.common.CompressionActivator)1 OsmHandler (org.openstreetmap.osmosis.xml.v0_6.impl.OsmHandler)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1