use of uk.me.parabola.imgfmt.fs.FileSystem in project mkgmap by openstreetmap.
the class Map method createMap.
/**
* Create a complete map. This consists of (at least) three
* files that all have the same basename and different extensions.
*
* @param mapname The name of the map. This is an 8 digit number as a
* string.
* @param params Parameters that describe the file system that the map
* will be created in.
* @return A map object that holds together all the files that make it up.
* @throws FileExistsException If the file already exists and we do not
* want to overwrite it.
* @throws FileNotWritableException If the file cannot
* be opened for write.
*/
public static Map createMap(String mapname, String outputdir, FileSystemParam params, String mapnumber, Sort sort) throws FileExistsException, FileNotWritableException {
Map m = new Map();
m.mapName = mapname;
String outFilename = Utils.joinPath(outputdir, mapname, "img");
FileSystem fs = ImgFS.createFs(outFilename, params);
m.filename = outFilename;
m.fileSystem = fs;
m.rgnFile = new RGNFile(m.fileSystem.create(mapnumber + ".RGN"));
m.treFile = new TREFile(m.fileSystem.create(mapnumber + ".TRE"));
m.lblFile = new LBLFile(m.fileSystem.create(mapnumber + ".LBL"), sort);
int mapid;
try {
mapid = Integer.parseInt(mapnumber);
} catch (NumberFormatException e) {
mapid = 0;
}
m.mapId = mapid;
m.treFile.setMapId(mapid);
m.fileSystem = fs;
return m;
}
use of uk.me.parabola.imgfmt.fs.FileSystem in project mkgmap by openstreetmap.
the class FileInfo method imgInfo.
/**
* An IMG file, this involves real work. We have to read in the file and
* extract several pieces of information from it.
*
* @param inputName The name of the file.
* @return The information obtained.
* @throws FileNotFoundException If the file doesn't exist.
*/
private static FileInfo imgInfo(String inputName) throws FileNotFoundException {
try (FileSystem imgFs = ImgFS.openFs(inputName)) {
FileSystemParam params = imgFs.fsparam();
log.info("Desc", params.getMapDescription());
log.info("Blocksize", params.getBlockSize());
FileInfo info = new FileInfo(inputName, UNKNOWN_KIND);
info.setDescription(params.getMapDescription());
File f = new File(inputName);
String name = f.getName();
if (OverviewBuilder.isOverviewImg(name))
name = OverviewBuilder.getMapName(name);
int dot = name.lastIndexOf('.');
if (dot < 0) {
name = "0";
} else {
if (dot > name.length())
dot = name.length();
if (dot > 8)
dot = 8;
name = name.substring(0, dot);
}
info.setMapname(name);
boolean hasTre = false;
DirectoryEntry treEnt = null;
List<DirectoryEntry> entries = imgFs.list();
for (DirectoryEntry ent : entries) {
if (ent.isSpecial())
continue;
log.info("file", ent.getFullName());
String ext = ent.getExt();
if ("TRE".equals(ext)) {
info.setTresize(ent.getSize());
info.setInnername(ent.getName());
hasTre = true;
treEnt = ent;
} else if ("RGN".equals(ext)) {
int size = ent.getSize();
info.setRgnsize(size);
} else if ("LBL".equals(ext)) {
info.setLblsize(ent.getSize());
lblInfo(imgFs, ent, info);
} else if ("NET".equals(ext)) {
info.setNetsize(ent.getSize());
} else if ("NOD".equals(ext)) {
info.setNodsize(ent.getSize());
} else if ("DEM".equals(ext)) {
info.setDemsize(ent.getSize());
} else if ("MDR".equals(ext)) {
// It is not actually a regular img file, so change the kind.
info.setKind(MDR_KIND);
} else if ("MPS".equals(ext)) {
// This is a gmapsupp file containing several maps.
info.setKind(GMAPSUPP_KIND);
info.mpsName = ent.getFullName();
}
info.subFiles.add(new SubFileInfo(ent.getFullName(), ent.getSize()));
}
if (hasTre)
treInfo(imgFs, treEnt, info);
if (info.getKind() == UNKNOWN_KIND && hasTre)
info.setKind(IMG_KIND);
return info;
}
}
use of uk.me.parabola.imgfmt.fs.FileSystem in project mkgmap by openstreetmap.
the class GmapiBuilder method unzipImg.
private static void unzipImg(String srcImgName, Path destDir) throws IOException {
FileSystem fs = ImgFS.openFs(srcImgName);
for (DirectoryEntry ent : fs.list()) {
String fullname = ent.getFullName();
try (ImgChannel f = fs.open(fullname, "r")) {
String name = displayName(fullname);
if (Objects.equals(name, "."))
continue;
Files.createDirectories(destDir);
copyToFile(f, destDir.resolve(name));
}
}
}
use of uk.me.parabola.imgfmt.fs.FileSystem in project mkgmap by openstreetmap.
the class FileCopier method addMpsFile.
/**
* Add a complete pre-existing mps file to the mps file we are currently
* building for this gmapsupp.
* @param info The details of the gmapsupp file that we need to extract the
*/
private void addMpsFile(FileInfo info) {
String name = info.getFilename();
try (FileSystem fs = ImgFS.openFs(name)) {
MpsFileReader mr = new MpsFileReader(fs.open(info.getMpsName(), "r"), info.getCodePage());
for (MapBlock block : mr.getMaps()) mpsFile.addMap(block);
for (ProductBlock b : mr.getProducts()) mpsFile.addProduct(b);
mr.close();
} catch (IOException e) {
log.error("Could not read MPS file from gmapsupp", e);
}
}
Aggregations