Search in sources :

Example 16 with ImgChannel

use of uk.me.parabola.imgfmt.fs.ImgChannel 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 17 with ImgChannel

use of uk.me.parabola.imgfmt.fs.ImgChannel in project mkgmap by openstreetmap.

the class FileCopier method addImg.

private void addImg(FileSystem outfs, FileInfo info) {
    FileCopier fc = new FileCopier(info.getFilename());
    List<SubFileInfo> subFiles = info.subFiles();
    for (SubFileInfo sf : subFiles) {
        try {
            ImgChannel chan = outfs.create(sf.getName());
            Closeable sync = fc.add(sf.getName(), chan);
            ((FileLink) chan).link(sf, sync);
        } catch (FileExistsException e) {
            log.warn("Could not copy " + sf.getName(), e);
        }
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) Closeable(java.io.Closeable) FileLink(uk.me.parabola.imgfmt.sys.FileLink) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 18 with ImgChannel

use of uk.me.parabola.imgfmt.fs.ImgChannel in project mkgmap by openstreetmap.

the class MdrBuilder method init.

/**
 * Create the mdr file and initialise.
 * It has a name that is based on the overview-mapname option, as does
 * the associated MDX file.
 *
 * @param args The command line arguments.
 */
public void init(CommandArgs args) {
    String name = args.get("overview-mapname", "osmmap");
    String outputDir = args.getOutputDir();
    outputName = Utils.joinPath(outputDir, name + "_mdr.img");
    ImgChannel mdrChan;
    try {
        // Create the .img file system/archive
        FileSystemParam params = new FileSystemParam();
        tmpName = File.createTempFile("mdr", null, new File(outputDir));
        tmpName.deleteOnExit();
        imgfs = ImgFS.createFs(tmpName.getPath(), params);
        // Create the MDR file within the .img
        mdrChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".MDR");
    } catch (IOException e) {
        throw new ExitException("Could not create global index file");
    }
    // Create the sort description
    Sort sort = SrtTextReader.sortForCodepage(args.getCodePage());
    // Set the options that we are using for the mdr.
    MdrConfig config = new MdrConfig();
    config.setHeaderLen(568);
    config.setWritable(true);
    config.setForDevice(false);
    config.setOutputDir(outputDir);
    config.setSort(sort);
    config.setIndexOptions(args);
    // Wrap the MDR channel with the MDRFile object
    mdrFile = new MDRFile(mdrChan, config);
    try {
        ImgChannel srtChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".SRT");
        SRTFile srtFile = new SRTFile(srtChan);
        srtFile.setSort(sort);
        srtFile.write();
    // Do not close srtFile here
    } catch (FileExistsException e) {
        throw new ExitException("Could not create SRT file within index file");
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MdrConfig(uk.me.parabola.imgfmt.app.mdr.MdrConfig) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) IOException(java.io.IOException) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) File(java.io.File) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Aggregations

ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)18 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)9 FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)8 Test (org.junit.Test)6 File (java.io.File)5 IOException (java.io.IOException)5 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)5 ByteBuffer (java.nio.ByteBuffer)4 SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)3 Sort (uk.me.parabola.imgfmt.app.srt.Sort)3 TREFileReader (uk.me.parabola.imgfmt.app.trergn.TREFileReader)3 FileNotFoundException (java.io.FileNotFoundException)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)2 DirectoryEntry (uk.me.parabola.imgfmt.fs.DirectoryEntry)2 FileLink (uk.me.parabola.imgfmt.sys.FileLink)2 Outputs (func.lib.Outputs)1 Closeable (java.io.Closeable)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 LinkedHashMap (java.util.LinkedHashMap)1