Search in sources :

Example 11 with MapFailedException

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

the class TypCompiler method compile.

/**
 * Read and compile a TYP file, returning the compiled form.
 *
 * @param filename The input filename.
 * @param charset The character set to use to read this file. We should have already determined
 * that this character set is valid and can be used to read the file.
 * @param sort The sort information from command line options, used for the output code page
 * only. If null, then the code page set by CodePage in the typ.txt file will be used.
 *
 * @return The compiled form as a data structure.
 * @throws FileNotFoundException If the file doesn't exist.
 * @throws SyntaxException All user correctable problems in the input file.
 */
private TypData compile(String filename, String charset, Sort sort) throws FileNotFoundException, SyntaxException {
    TypTextReader tr = new TypTextReader();
    TypData data = tr.getData();
    data.setSort(sort);
    try {
        Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), charset));
        try {
            tr.read(filename, r);
        } finally {
            Utils.closeFile(r);
        }
    } catch (UnsupportedEncodingException e) {
        // Not likely to happen as we should have already used this character set!
        throw new MapFailedException("Unsupported character set", e);
    }
    return tr.getData();
}
Also used : InputStreamReader(java.io.InputStreamReader) TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) BufferedReader(java.io.BufferedReader) TypTextReader(uk.me.parabola.mkgmap.typ.TypTextReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TypTextReader(uk.me.parabola.mkgmap.typ.TypTextReader) FileInputStream(java.io.FileInputStream)

Example 12 with MapFailedException

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

the class LBLFile method newLabel.

/**
 * Add a new label with the given text.  Labels are shared, so that identical
 * text is always represented by the same label.
 *
 * @param text The text of the label, it will be in uppercase.
 * @return A reference to the created label.
 */
public Label newLabel(String text) {
    EncodedText encodedText = textEncoder.encodeText(text);
    Label l = labelCache.get(encodedText);
    if (l == null) {
        l = new Label(encodedText.getChars());
        labelCache.put(encodedText, l);
        l.setOffset(getNextLabelOffset());
        if (encodedText.getLength() > 0)
            getWriter().put(encodedText.getCtext(), 0, encodedText.getLength());
        alignForNext();
        if (l.getOffset() > 0x3fffff)
            throw new MapFailedException("Overflow of LBL section");
    }
    return l;
}
Also used : MapFailedException(uk.me.parabola.imgfmt.MapFailedException) EncodedText(uk.me.parabola.imgfmt.app.labelenc.EncodedText) Label(uk.me.parabola.imgfmt.app.Label)

Example 13 with MapFailedException

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

the class Area method split.

/**
 * Split this area up into a number of smaller areas.
 *
 * @param xsplit The number of pieces to split this area into in the x
 * direction.
 * @param ysplit The number of pieces to split this area into in the y
 * direction.
 * @param resolutionShift round to this power of 2.
 * @return An array containing xsplit*ysplit areas or null if can't split in half.
 * @throws MapFailedException if more complex split operation couldn't be honoured.
 */
public Area[] split(int xsplit, int ysplit, int resolutionShift) {
    Area[] areas = new Area[xsplit * ysplit];
    int xstart;
    int xend;
    int ystart;
    int yend;
    int nAreas = 0;
    xstart = minLong;
    for (int x = 0; x < xsplit; x++) {
        if (x == xsplit - 1)
            xend = maxLong;
        else
            xend = roundPof2(xstart + (maxLong - xstart) / (xsplit - x), resolutionShift);
        ystart = minLat;
        for (int y = 0; y < ysplit; y++) {
            if (y == ysplit - 1)
                yend = maxLat;
            else
                yend = roundPof2(ystart + (maxLat - ystart) / (ysplit - y), resolutionShift);
            if (xstart < xend && ystart < yend) {
                Area a = new Area(ystart, xstart, yend, xend);
                // log.debug(x, y, a);
                log.debug("Area.split", minLat, minLong, maxLat, maxLong, "res", resolutionShift, "to", ystart, xstart, yend, xend);
                areas[nAreas++] = a;
            } else
                log.warn("Area.split", minLat, minLong, maxLat, maxLong, "res", resolutionShift, "can't", xsplit, ysplit);
            ystart = yend;
        }
        xstart = xend;
    }
    if (// no problem
    nAreas == areas.length)
        return areas;
    else // beware - MapSplitter.splitMaxSize requests split of 1/1 if the original area wasn't too big
    if (// failed to split in half
    nAreas == 1)
        return null;
    else if (areas.length == 1 && areas[0] == null)
        return null;
    else
        throw new MapFailedException("Area split shift align problems");
}
Also used : MapFailedException(uk.me.parabola.imgfmt.MapFailedException)

Example 14 with MapFailedException

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

the class BufferedImgFileWriter method ensureSize.

/**
 * Make sure there is enough room for the data we are about to write.
 *
 * @param length The amount of data.
 */
private void ensureSize(int length) {
    int needed = buf.position() + length;
    if (needed > (bufferSize - GUARD_SIZE)) {
        while (needed > (bufferSize - GUARD_SIZE)) bufferSize += GROW_SIZE;
        if (bufferSize > maxAllowedSize) {
            // up with something that is strictly true in all situations.
            throw new MapFailedException("There is not enough room in a single garmin map for all the input data." + " The .osm file should be split into smaller pieces first.");
        }
        ByteBuffer newb = ByteBuffer.allocate(bufferSize);
        newb.order(ByteOrder.LITTLE_ENDIAN);
        buf.flip();
        newb.put(buf);
        buf = newb;
    }
}
Also used : MapFailedException(uk.me.parabola.imgfmt.MapFailedException) ByteBuffer(java.nio.ByteBuffer)

Example 15 with MapFailedException

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

the class FileBackedImgFileWriter method putInt.

/**
 * Write out 4 byte value.
 *
 * @param val The value to write.
 */
public void putInt(int val) {
    try {
        file.write(val);
        file.write(val >> 8);
        file.write(val >> 16);
        file.write(val >> 24);
    } catch (IOException e) {
        throw new MapFailedException("could not write int to mdr tmp file");
    }
}
Also used : MapFailedException(uk.me.parabola.imgfmt.MapFailedException) IOException(java.io.IOException)

Aggregations

MapFailedException (uk.me.parabola.imgfmt.MapFailedException)22 IOException (java.io.IOException)11 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 TypData (uk.me.parabola.imgfmt.app.typ.TypData)3 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)3 FileInputStream (java.io.FileInputStream)2 OutOfMemoryError (java.lang.OutOfMemoryError)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)2 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)2 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 ByteBuffer (java.nio.ByteBuffer)1