Search in sources :

Example 1 with TypLabelException

use of uk.me.parabola.imgfmt.app.typ.TypLabelException in project mkgmap by openstreetmap.

the class TypCompiler method makeMap.

/**
 * The integration with mkgmap.
 *
 * @param args The options that are in force.
 * @param filename The input filename.
 * @return Returns the name of the file that was written. It depends on the family id.
 */
public String makeMap(CommandArgs args, String filename) {
    assert filename.toLowerCase().endsWith(".txt");
    CharsetProbe probe = new CharsetProbe();
    String readCharset = probe.probeCharset(filename);
    TypData data;
    try {
        data = compile(filename, readCharset, args.getSort());
    } catch (SyntaxException e) {
        throw new MapFailedException("Compiling TYP txt file: " + e.getMessage());
    } catch (FileNotFoundException e) {
        throw new MapFailedException("Could not open TYP file " + filename + " to read");
    }
    TypParam param = data.getParam();
    int family = args.get("family-id", -1);
    int product = args.get("product-id", -1);
    int cp = args.get("code-page", -1);
    if (family != -1)
        param.setFamilyId(family);
    if (product != -1)
        param.setProductId(product);
    if (cp != -1)
        param.setCodePage(cp);
    File outFile = new File(filename);
    String outName = outFile.getName();
    int last;
    if (outName.length() > 4 && (last = outName.lastIndexOf('.')) > 0)
        outName = outName.substring(0, last);
    outName += ".typ";
    outFile = new File(args.getOutputDir(), outName);
    try {
        writeTyp(data, outFile);
    } catch (TypLabelException e) {
        throw new MapFailedException("TYP file cannot be written in code page " + data.getSort().getCodepage());
    } catch (IOException e) {
        throw new MapFailedException("Error while writing typ file", e);
    }
    return outFile.getPath();
}
Also used : TypLabelException(uk.me.parabola.imgfmt.app.typ.TypLabelException) TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) TypParam(uk.me.parabola.imgfmt.app.typ.TypParam) IOException(java.io.IOException) TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) File(java.io.File)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)1 TypData (uk.me.parabola.imgfmt.app.typ.TypData)1 TypLabelException (uk.me.parabola.imgfmt.app.typ.TypLabelException)1 TypParam (uk.me.parabola.imgfmt.app.typ.TypParam)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1