Search in sources :

Example 11 with ExitException

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

the class TdbBuilder method addToTdb.

/**
 * Add the information about the current map to the tdb file.
 *
 * @param finfo Information about the current .img file.
 */
private void addToTdb(FileInfo finfo) {
    DetailMapBlock detail = new DetailMapBlock(tdbVersion);
    detail.setArea(finfo.getBounds());
    String mapname = finfo.getMapname();
    String mapdesc = finfo.getDescription();
    detail.setMapName(mapname);
    String desc = mapdesc + " (" + mapname + ')';
    detail.setDescription(desc);
    detail.setSubFiles(finfo.subFiles());
    log.info("overview-mapname", overviewMapname);
    log.info("overview-mapnumber", parent);
    detail.setParentMapNumber(parent);
    tdb.addDetail(detail);
    String[] msgs = finfo.getLicenseInfo();
    for (String m : msgs) tdb.addCopyright(m);
    MapReader mapReader = null;
    String filename = finfo.getFilename();
    try {
        mapReader = new MapReader(filename);
        msgs = mapReader.getCopyrights();
        boolean found = false;
        for (String[] block : copyrightMsgs) {
            if (Arrays.deepEquals(block, msgs)) {
                found = true;
                break;
            }
        }
        if (!found) {
            copyrightMsgs.add(msgs);
            for (String m : msgs) tdb.addCopyright(m);
        }
    } catch (FileNotFoundException e) {
        throw new ExitException("Could not open " + filename + " when creating tdb file");
    } finally {
        Utils.closeFile(mapReader);
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) DetailMapBlock(uk.me.parabola.tdbfmt.DetailMapBlock) FileNotFoundException(java.io.FileNotFoundException) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 12 with ExitException

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

the class LevelInfo method createFromString.

/**
 * Convert a string into an array of LevelInfo structures.
 */
public static LevelInfo[] createFromString(String levelSpec) {
    String[] desc = levelSpec.split("[, \\t\\n]+");
    LevelInfo[] levels = new LevelInfo[desc.length];
    int count = 0;
    for (String s : desc) {
        String[] keyVal = s.split("[=:]");
        if (keyVal == null || keyVal.length < 2) {
            throw new ExitException("Error: incorrect level specification " + levelSpec);
        }
        try {
            int key = Integer.parseInt(keyVal[0]);
            if (key < 0 || key > 16)
                throw new ExitException("Error: Level value out of range 0-16: " + s + " in levels specification " + levelSpec);
            int value = Integer.parseInt(keyVal[1]);
            if (value <= 0 || value > 24)
                throw new ExitException("Error: Resolution value out of range 0-24: " + s + " in levels specification " + levelSpec);
            levels[count] = new LevelInfo(key, value);
        } catch (NumberFormatException e) {
            throw new ExitException("Error: Levels specification not all numbers: " + levelSpec + " check " + s);
        }
        count++;
    }
    Arrays.sort(levels);
    // garmin to crash.
    if (levels.length > 8)
        throw new ExitException("Too many levels, the maximum is 8");
    return levels;
}
Also used : ExitException(uk.me.parabola.imgfmt.ExitException)

Example 13 with ExitException

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

the class Main method listStyles.

private void listStyles() {
    String[] names;
    try {
        StyleFileLoader loader = StyleFileLoader.createStyleLoader(styleFile, null);
        names = loader.list();
        loader.close();
    } catch (FileNotFoundException e) {
        log.debug("didn't find style file", e);
        throw new ExitException("Could not list style file " + styleFile);
    }
    Arrays.sort(names);
    System.out.println("The following styles are available:");
    for (String name : names) {
        Style style = readOneStyle(name, false);
        if (style == null)
            continue;
        StyleInfo info = style.getInfo();
        System.out.format("%-15s %6s: %s\n", searchedStyleName, info.getVersion(), info.getSummary());
        if (verbose) {
            for (String s : info.getLongDescription().split("\n")) System.out.printf("\t%s\n", s.trim());
        }
    }
}
Also used : StyleFileLoader(uk.me.parabola.mkgmap.osmstyle.StyleFileLoader) FileNotFoundException(java.io.FileNotFoundException) StyleInfo(uk.me.parabola.mkgmap.reader.osm.StyleInfo) Style(uk.me.parabola.mkgmap.reader.osm.Style) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 14 with ExitException

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

the class Main method checkStyles.

/**
 * Check one or all styles in the path given in styleFile.
 */
private void checkStyles() {
    String[] names;
    try {
        StyleFileLoader loader = StyleFileLoader.createStyleLoader(styleFile, null);
        names = loader.list();
        loader.close();
    } catch (FileNotFoundException e) {
        log.debug("didn't find style file", e);
        throw new ExitException("Could not check style file " + styleFile);
    }
    Arrays.sort(names);
    if (styleOption == null) {
        if (names.length > 1)
            System.out.println("The following styles are available:");
        else
            System.out.println("Found one style in " + styleFile);
    }
    int checked = 0;
    for (String name : names) {
        if (styleOption != null && !Objects.equals(name, styleOption))
            continue;
        if (names.length > 1) {
            System.out.println("checking style: " + name);
        }
        ++checked;
        boolean performChecks = true;
        if (Objects.equals("classpath:styles", styleFile) && !Objects.equals("default", name)) {
            performChecks = false;
        }
        Style style = readOneStyle(name, performChecks);
        if (style == null) {
            System.out.println("could not open style " + name);
        }
    }
    if (checked == 0)
        System.out.println("could not open style " + styleOption + " in " + styleFile);
    System.out.println("finished check-styles");
}
Also used : StyleFileLoader(uk.me.parabola.mkgmap.osmstyle.StyleFileLoader) FileNotFoundException(java.io.FileNotFoundException) Style(uk.me.parabola.mkgmap.reader.osm.Style) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 15 with ExitException

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

the class Main method mainStart.

/**
 * The main program to make or combine maps.  We now use a two pass process,
 * first going through the arguments and make any maps and collect names
 * to be used for creating summary files like the TDB and gmapsupp.
 *
 * @param args The command line arguments.
 */
private static int mainStart(String... args) {
    Instant start = Instant.now();
    System.out.println("Time started: " + new Date());
    // We need at least one argument.
    if (args.length < 1) {
        printUsage();
        printHelp(System.err, getLang(), "options");
        return 0;
    }
    Main mm = new Main();
    int numExitExceptions = 0;
    try {
        // Read the command line arguments and process each filename found.
        CommandArgsReader commandArgs = new CommandArgsReader(mm);
        commandArgs.setValidOptions(getValidOptions(System.err));
        commandArgs.readArgs(args);
    } catch (OutOfMemoryError e) {
        ++numExitExceptions;
        System.err.println(e);
        if (mm.maxJobs > 1)
            System.err.println("Try using the mkgmap --max-jobs option with a value less than " + mm.maxJobs + " to reduce the memory requirement, or use the Java -Xmx option to increase the available heap memory.");
        else
            System.err.println("Try using the Java -Xmx option to increase the available heap memory.");
    } catch (MapFailedException e) {
        // one of the combiners failed
        e.printStackTrace();
        ++numExitExceptions;
    } catch (ExitException e) {
        ++numExitExceptions;
        String message = e.getMessage();
        Throwable cause = e.getCause();
        while (cause != null) {
            message += "\r\n" + cause.toString();
            cause = cause.getCause();
        }
        System.err.println(message);
    }
    System.out.println("Number of ExitExceptions: " + numExitExceptions);
    System.out.println("Time finished: " + new Date());
    Duration duration = Duration.between(start, Instant.now());
    long seconds = duration.getSeconds();
    if (seconds > 0) {
        long hours = seconds / 3600;
        seconds -= hours * 3600;
        long minutes = seconds / 60;
        seconds -= minutes * 60;
        System.out.println("Total time taken: " + (hours > 0 ? hours + (hours > 1 ? " hours " : " hour ") : "") + (minutes > 0 ? minutes + (minutes > 1 ? " minutes " : " minute ") : "") + (seconds > 0 ? seconds + (seconds > 1 ? " seconds" : " second") : ""));
    } else
        System.out.println("Total time taken: " + duration.getNano() / 1000000 + " ms");
    if (numExitExceptions > 0 || mm.getProgramRC() != 0) {
        return 1;
    }
    return 0;
}
Also used : CommandArgsReader(uk.me.parabola.mkgmap.CommandArgsReader) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) Instant(java.time.Instant) Duration(java.time.Duration) ExitException(uk.me.parabola.imgfmt.ExitException) Date(java.util.Date) OutOfMemoryError(java.lang.OutOfMemoryError)

Aggregations

ExitException (uk.me.parabola.imgfmt.ExitException)25 IOException (java.io.IOException)10 FileNotFoundException (java.io.FileNotFoundException)9 File (java.io.File)7 ArrayList (java.util.ArrayList)5 FileInputStream (java.io.FileInputStream)4 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)4 InputStream (java.io.InputStream)3 ByteBuffer (java.nio.ByteBuffer)3 Map (uk.me.parabola.imgfmt.app.map.Map)3 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)3 OutOfMemoryError (java.lang.OutOfMemoryError)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 FormatStyle (java.time.format.FormatStyle)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2