use of uk.me.parabola.imgfmt.ExitException in project mkgmap by openstreetmap.
the class SrtTextReader method sortForCodepage.
/**
* Find and read in the default sort description for the given codepage.
*/
public static Sort sortForCodepage(int codepage) {
String name = "sort/cp" + codepage + ".txt";
InputStream is = Sort.class.getClassLoader().getResourceAsStream(name);
if (is == null) {
if (codepage == 1252)
throw new ExitException("No sort description for code-page 1252 available");
Sort defaultSort = SrtTextReader.sortForCodepage(1252);
defaultSort.setCodepage(codepage);
defaultSort.setDescription("Default sort");
return defaultSort;
}
try {
InputStreamReader r = new InputStreamReader(is, "utf-8");
SrtTextReader sr = new SrtTextReader(r);
return sr.getSort();
} catch (IOException e) {
return SrtTextReader.sortForCodepage(codepage);
}
}
use of uk.me.parabola.imgfmt.ExitException in project mkgmap by openstreetmap.
the class Sort method add.
public void add(int ch, int primary, int secondary, int tertiary, int flags) {
ensurePage(ch >>> 8);
if (getPrimary(ch) != 0)
throw new ExitException(String.format("Repeated primary index 0x%x", ch & 0xff));
setPrimary(ch, primary);
setSecondary(ch, secondary);
setTertiary(ch, tertiary);
setFlags(ch, flags);
int numExp = (flags >> 4) & 0xf;
if (numExp + 1 > maxExpSize)
maxExpSize = numExp + 1;
}
use of uk.me.parabola.imgfmt.ExitException in project mkgmap by openstreetmap.
the class MapBuilder method getMapInfo.
/**
* Set all the information that appears in the header.
*/
private void getMapInfo() {
if (licenseFileName != null) {
List<String> licenseArray = new ArrayList<>();
try {
File file = new File(licenseFileName);
licenseArray = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
} catch (Exception e) {
throw new ExitException("Error reading license file " + licenseFileName, e);
}
if ((licenseArray.size() > 0) && licenseArray.get(0).startsWith("\ufeff"))
licenseArray.set(0, licenseArray.get(0).substring(1));
UnaryOperator<String> replaceVariables = s -> s.replace("$MKGMAP_VERSION$", Version.VERSION).replace("$JAVA_VERSION$", System.getProperty("java.version")).replace("$YEAR$", Integer.toString(now.getYear())).replace("$LONGDATE$", now.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG))).replace("$SHORTDATE$", now.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT))).replace("$TIME$", now.toLocalTime().toString().substring(0, 5));
licenseArray.replaceAll(replaceVariables);
mapInfo.addAll(licenseArray);
} else {
mapInfo.add("Map data (c) OpenStreetMap and its contributors");
mapInfo.add("http://www.openstreetmap.org/copyright");
mapInfo.add("");
mapInfo.add("This map data is made available under the Open Database License:");
mapInfo.add("http://opendatacommons.org/licenses/odbl/1.0/");
mapInfo.add("Any rights in individual contents of the database are licensed under the");
mapInfo.add("Database Contents License: http://opendatacommons.org/licenses/dbcl/1.0/");
mapInfo.add("");
// Pad the version number with spaces so that version
// strings that are different lengths do not change the size and
// offsets of the following sections.
mapInfo.add("Map created with mkgmap-r" + String.format("%-10s", Version.VERSION));
mapInfo.add("Program released under the GPL");
}
}
use of uk.me.parabola.imgfmt.ExitException in project mkgmap by openstreetmap.
the class GmapiBuilder method copyToFile.
private static void copyToFile(ImgChannel f, Path dest) {
ByteBuffer buf = ByteBuffer.allocate(8 * 1024);
try (ByteChannel outchan = Files.newByteChannel(dest, CREATE, WRITE, TRUNCATE_EXISTING)) {
while (f.read(buf) > 0) {
buf.flip();
outchan.write(buf);
buf.compact();
}
} catch (IOException e) {
throw new ExitException("Cannot write file " + e);
}
}
use of uk.me.parabola.imgfmt.ExitException in project mkgmap by openstreetmap.
the class OverviewBuilder method writeOverviewMap.
/**
* Write out the overview map.
*/
private void writeOverviewMap() {
if (overviewSource.mapLevels() == null)
return;
MapBuilder mb = new MapBuilder();
mb.setEnableLineCleanFilters(false);
FileSystemParam params = new FileSystemParam();
params.setMapDescription(areaName);
mb.setCopyrights(creMsgList(copyrightMsgs));
mb.setMapInfo(creMsgList(licenseInfos));
try {
if (codepage == null) {
// should not happen
codepage = 0;
}
Sort sort = SrtTextReader.sortForCodepage(codepage);
Map map = Map.createMap(overviewMapname, outputDir, params, overviewMapnumber, sort);
if (!demProps.isEmpty()) {
map.config(demProps);
mb.config(demProps);
}
if (encodingType != null) {
map.getLblFile().setEncoder(encodingType, codepage);
}
mb.makeMap(map, overviewSource);
map.close();
} catch (FileExistsException e) {
throw new ExitException("Could not create overview map", e);
} catch (FileNotWritableException e) {
throw new ExitException("Could not write to overview map", e);
}
}
Aggregations