Search in sources :

Example 6 with FormatException

use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.

the class OsmXmlHandler method parse.

@Override
public void parse(InputStream is) throws FormatException {
    try {
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setXIncludeAware(true);
        parserFactory.setNamespaceAware(true);
        SAXParser parser = parserFactory.newSAXParser();
        try {
            SaxHandler saxHandler = new SaxHandler();
            // parse the xml file
            parser.parse(is, saxHandler);
        } catch (IOException e) {
            throw new FormatException("Error reading file", e);
        }
    } catch (SAXException e) {
        throw new FormatException("Error parsing file", e);
    } catch (ParserConfigurationException e) {
        throw new FormatException("Internal error configuring xml parser", e);
    }
}
Also used : SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FormatException(uk.me.parabola.imgfmt.FormatException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 7 with FormatException

use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.

the class SeaGenerator method loadPrecompTile.

/**
 * Loads the precomp sea tile with the given filename.
 * @param filename the filename of the precomp sea tile
 * @return all ways of the tile
 * @throws FileNotFoundException if the tile could not be found
 */
private Collection<Way> loadPrecompTile(InputStream is, String filename) {
    OsmPrecompSeaDataSource src = new OsmPrecompSeaDataSource();
    EnhancedProperties props = new EnhancedProperties();
    props.setProperty("style", "empty");
    src.config(props);
    log.info("Started loading coastlines from", filename);
    try {
        src.parse(is, filename);
    } catch (FormatException e) {
        log.error("Failed to read " + filename);
        log.error(e);
    }
    log.info("Finished loading coastlines from", filename);
    return src.getElementSaver().getWays().values();
}
Also used : EnhancedProperties(uk.me.parabola.util.EnhancedProperties) FormatException(uk.me.parabola.imgfmt.FormatException)

Example 8 with FormatException

use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.

the class OsmBinHandler method parse.

@Override
public void parse(InputStream is) {
    try {
        BinParser reader = new BinParser();
        BlockInputStream stream = new BlockInputStream(is, reader);
        stream.process();
    } catch (NoClassDefFoundError e) {
        throw new FormatException("Failed to read binary file, probably missing protobuf.jar");
    } catch (IOException e) {
        throw new FormatException("Failed to read binary file");
    }
}
Also used : BlockInputStream(crosby.binary.file.BlockInputStream) IOException(java.io.IOException) FormatException(uk.me.parabola.imgfmt.FormatException)

Example 9 with FormatException

use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.

the class BoundaryPreprocessor method createRawData.

/**
 * Parse OSM data and create boundaries. Distribute the boundaries on a grid
 * with a fixed raster.
 * @return true if data was successfully written, else false
 */
private boolean createRawData() {
    File boundsDirectory = new File(outDir);
    BoundarySaver saver = new BoundarySaver(boundsDirectory, BoundarySaver.RAW_DATA_FORMAT);
    OsmBoundaryDataSource dataSource = new OsmBoundaryDataSource();
    dataSource.setBoundarySaver(saver);
    log.info("Started loading", boundaryFilename);
    try {
        dataSource.load(boundaryFilename, false);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    } catch (FormatException e) {
        e.printStackTrace();
        return false;
    }
    saver.setBbox(dataSource.getBounds());
    log.info("Finished loading", boundaryFilename);
    saver.end();
    return true;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FormatException(uk.me.parabola.imgfmt.FormatException)

Aggregations

FormatException (uk.me.parabola.imgfmt.FormatException)9 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)3 File (java.io.File)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 SAXException (org.xml.sax.SAXException)2 EnhancedProperties (uk.me.parabola.util.EnhancedProperties)2 BlockInputStream (crosby.binary.file.BlockInputStream)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1