Search in sources :

Example 16 with FileSystem

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;
}
Also used : TREFile(uk.me.parabola.imgfmt.app.trergn.TREFile) RGNFile(uk.me.parabola.imgfmt.app.trergn.RGNFile) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile)

Example 17 with FileSystem

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;
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry) File(java.io.File)

Example 18 with FileSystem

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));
        }
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry)

Example 19 with FileSystem

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);
    }
}
Also used : ProductBlock(uk.me.parabola.imgfmt.mps.ProductBlock) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) MapBlock(uk.me.parabola.imgfmt.mps.MapBlock) IOException(java.io.IOException) MpsFileReader(uk.me.parabola.imgfmt.mps.MpsFileReader)

Aggregations

FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)19 Test (org.junit.Test)11 File (java.io.File)8 DirectoryEntry (uk.me.parabola.imgfmt.fs.DirectoryEntry)8 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)8 ByteBuffer (java.nio.ByteBuffer)4 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)3 Outputs (func.lib.Outputs)2 RangeMatcher (func.lib.RangeMatcher)2 IOException (java.io.IOException)2 MpsFileReader (uk.me.parabola.imgfmt.mps.MpsFileReader)2 FileNotFoundException (java.io.FileNotFoundException)1 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)1 Point (uk.me.parabola.imgfmt.app.trergn.Point)1 RGNFile (uk.me.parabola.imgfmt.app.trergn.RGNFile)1 TREFile (uk.me.parabola.imgfmt.app.trergn.TREFile)1 TREFileReader (uk.me.parabola.imgfmt.app.trergn.TREFileReader)1 MapBlock (uk.me.parabola.imgfmt.mps.MapBlock)1 ProductBlock (uk.me.parabola.imgfmt.mps.ProductBlock)1 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)1