Search in sources :

Example 1 with SectionWriter

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

the class TYPFile method writeLabels.

private void writeLabels(ImgFileWriter in) {
    if (data.getIcons().isEmpty())
        return;
    SectionWriter writer = header.getLabels().makeSectionWriter(in);
    List<SortKey<TypIconSet>> keys = new ArrayList<SortKey<TypIconSet>>();
    Sort sort = data.getSort();
    for (TypIconSet icon : data.getIcons()) {
        String label = icon.getLabel();
        if (label != null) {
            SortKey<TypIconSet> key = sort.createSortKey(icon, label);
            keys.add(key);
        }
    }
    Collections.sort(keys);
    // Offset 0 is reserved to mean no label.
    writer.put((byte) 0);
    for (SortKey<TypIconSet> key : keys) {
        int off = writer.position();
        TypIconSet icon = key.getObject();
        int type = icon.getTypeForFile();
        String label = icon.getLabel();
        if (label != null) {
            CharBuffer cb = CharBuffer.wrap(label);
            CharsetEncoder encoder = data.getEncoder();
            try {
                ByteBuffer buffer = encoder.encode(cb);
                writer.put(buffer);
                // If we succeeded then note offsets for indexes
                strToType.put(off, type);
                typeToStr.put(type, off);
            } catch (CharacterCodingException ignore) {
                String name = encoder.charset().name();
                throw new TypLabelException(name);
            }
            writer.put((byte) 0);
        }
    }
    Utils.closeFile(writer);
}
Also used : SectionWriter(uk.me.parabola.imgfmt.app.SectionWriter) ArrayList(java.util.ArrayList) CharBuffer(java.nio.CharBuffer) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey) CharacterCodingException(java.nio.charset.CharacterCodingException) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer) Sort(uk.me.parabola.imgfmt.app.srt.Sort)

Example 2 with SectionWriter

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

the class TYPFile method writeSection.

private void writeSection(ImgFileWriter writer, Section dataSection, Section indexSection, List<? extends TypElement> elementData) {
    Collections.sort(elementData);
    SectionWriter subWriter = dataSection.makeSectionWriter(writer);
    CharsetEncoder encoder = data.getEncoder();
    for (TypElement elem : elementData) elem.write(subWriter, encoder);
    Utils.closeFile(subWriter);
    int size = dataSection.getSize();
    int typeSize = indexSection.getItemSize();
    int psize = Utils.numberToPointerSize(size);
    indexSection.setItemSize((char) (typeSize + psize));
    subWriter = indexSection.makeSectionWriter(writer);
    for (TypElement elem : elementData) {
        int offset = elem.getOffset();
        int type = elem.getTypeForFile();
        subWriter.putN(typeSize, type);
        subWriter.putN(psize, offset);
    }
    Utils.closeFile(subWriter);
    zapZero(dataSection, indexSection);
}
Also used : SectionWriter(uk.me.parabola.imgfmt.app.SectionWriter) CharsetEncoder(java.nio.charset.CharsetEncoder)

Example 3 with SectionWriter

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

the class NODFile method writeBoundary.

/**
 * Write the boundary node table (NOD3).
 */
private void writeBoundary() {
    log.info("writeBoundary");
    Collections.sort(boundary);
    ImgFileWriter writer = new SectionWriter(getWriter(), nodHeader.getBoundarySection());
    boolean debug = log.isDebugEnabled();
    for (RouteNode node : boundary) {
        if (debug)
            log.debug("wrting nod3", writer.position());
        node.writeNod3OrNod4(writer);
    }
    if (debug)
        log.debug("ending nod3", writer.position());
    nodHeader.setBoundarySize(writer.position());
}
Also used : SectionWriter(uk.me.parabola.imgfmt.app.SectionWriter) ImgFileWriter(uk.me.parabola.imgfmt.app.ImgFileWriter) BufferedImgFileWriter(uk.me.parabola.imgfmt.app.BufferedImgFileWriter)

Example 4 with SectionWriter

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

the class NODFile method writeRoadData.

/**
 * Write the road data (NOD2).
 */
private void writeRoadData() {
    log.info("writeRoadData");
    ImgFileWriter writer = new SectionWriter(getWriter(), nodHeader.getRoadSection());
    boolean debug = log.isDebugEnabled();
    for (RoadDef rd : roads) {
        if (debug)
            log.debug("wrting nod2", writer.position());
        rd.writeNod2(writer);
    }
    if (debug)
        log.debug("ending nod2", writer.position());
    nodHeader.setRoadSize(writer.position());
}
Also used : SectionWriter(uk.me.parabola.imgfmt.app.SectionWriter) ImgFileWriter(uk.me.parabola.imgfmt.app.ImgFileWriter) BufferedImgFileWriter(uk.me.parabola.imgfmt.app.BufferedImgFileWriter)

Example 5 with SectionWriter

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

the class NODFile method writePost.

public void writePost() {
    ImgFileWriter writer = new SectionWriter(getWriter(), nodHeader.getNodeSection());
    for (RouteCenter rc : centers) {
        rc.writePost(writer);
    }
    // Refresh the header
    position(0);
    getHeader().writeHeader(getWriter());
}
Also used : SectionWriter(uk.me.parabola.imgfmt.app.SectionWriter) ImgFileWriter(uk.me.parabola.imgfmt.app.ImgFileWriter) BufferedImgFileWriter(uk.me.parabola.imgfmt.app.BufferedImgFileWriter)

Aggregations

SectionWriter (uk.me.parabola.imgfmt.app.SectionWriter)11 BufferedImgFileWriter (uk.me.parabola.imgfmt.app.BufferedImgFileWriter)7 ImgFileWriter (uk.me.parabola.imgfmt.app.ImgFileWriter)7 CharsetEncoder (java.nio.charset.CharsetEncoder)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Section (uk.me.parabola.imgfmt.app.Section)2 ByteBuffer (java.nio.ByteBuffer)1 CharBuffer (java.nio.CharBuffer)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 ArrayList (java.util.ArrayList)1 Sort (uk.me.parabola.imgfmt.app.srt.Sort)1 SortKey (uk.me.parabola.imgfmt.app.srt.SortKey)1