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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations