Search in sources :

Example 1 with DirectoryEntry

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

the class SrtFileReader method main.

/**
 * Read in a sort description text file and create a SRT from it.
 * @param args First arg is the text input file, the second is the name of the output file. The defaults are
 * in.txt and out.srt.
 */
public static void main(String[] args) throws IOException {
    String infile = "we2.srt";
    if (args.length > 0)
        infile = args[0];
    String outfile = "out.srt";
    if (args.length > 1)
        outfile = args[1];
    try {
        Files.delete(Paths.get(outfile, ""));
    } catch (Exception e) {
    }
    ImgChannel inChannel = null;
    FileSystem fs = null;
    try {
        if (infile.endsWith("srt"))
            inChannel = new FileImgChannel(infile, "r");
        else {
            fs = ImgFS.openFs(infile);
            List<DirectoryEntry> entries = fs.list();
            // Find the TRE entry
            String mapname = null;
            for (DirectoryEntry ent : entries) {
                if ("SRT".equals(ent.getExt())) {
                    mapname = ent.getName();
                    break;
                }
            }
            inChannel = fs.open(mapname + ".SRT", "r");
            ImgChannel chan = new FileImgChannel(outfile, "rw");
            SrtFileReader tr = new SrtFileReader(inChannel);
            tr.close();
            Sort sort1 = tr.getSort();
            SRTFile sf = new SRTFile(chan);
            sf.setSort(sort1);
            sf.write();
            sf.close();
            chan.close();
        }
    } catch (FileNotFoundException e) {
        System.err.println("Could not open file: " + infile);
    } finally {
        if (fs != null) {
            fs.close();
        }
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with DirectoryEntry

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

the class GmapsuppTest method testWithTypFile.

@Test
public void testWithTypFile() throws IOException {
    File f = new File(GMAPSUPP_IMG);
    assertFalse("does not pre-exist", f.exists());
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", Args.TEST_RESOURCE_IMG + "63240001.img", Args.TEST_RESOURCE_TYP + "test.txt");
    assertTrue("gmapsupp.img is created", f.exists());
    FileSystem fs = openFs(GMAPSUPP_IMG);
    DirectoryEntry entry = fs.lookup("63240001.TRE");
    assertNotNull("first file TRE", entry);
    assertEquals("first file TRE size", getFileSize(Args.TEST_RESOURCE_IMG + "63240001.img", "63240001.TRE"), entry.getSize());
    entry = fs.lookup("0000TEST.TYP");
    assertNotNull("contains typ file", entry);
}
Also used : FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry) File(java.io.File) Test(org.junit.Test)

Example 3 with DirectoryEntry

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

the class Directory method sync.

/**
 * Write out the directory to the file.  The file should be correctly
 * positioned by the caller.
 *
 * @throws IOException If there is a problem writing out any
 * of the directory entries.
 */
public void sync() throws IOException {
    // Save the current position
    long dirPosition = chan.position();
    // Skip the header/directory entry for now
    chan.position(dirPosition + DirectoryEntry.ENTRY_SIZE);
    // Write the blocks that will will contain the header blocks.
    for (DirectoryEntry dir : entries.values()) {
        Dirent ent = (Dirent) dir;
        if (!ent.isSpecial()) {
            log.debug("wrting ", dir.getFullName(), " at ", chan.position());
            log.debug("ent size", ent.getSize());
            ent.sync(chan);
        }
    }
    // Now go back and write in the directory entry for the header.
    chan.position(dirPosition);
    Dirent ent = (Dirent) entries.values().iterator().next();
    log.debug("ent header size", ent.getSize());
    ent.sync(chan);
}
Also used : DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry)

Example 4 with DirectoryEntry

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

the class SimpleTest method testPolish.

@Test
public void testPolish() throws FileNotFoundException {
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, Args.TEST_RESOURCE_MP + "test1.mp");
    FileSystem fs = openFs(Args.DEF_MAP_FILENAME);
    assertNotNull("file exists", fs);
    List<DirectoryEntry> entries = fs.list();
    int count = 0;
    for (DirectoryEntry ent : entries) {
        String ext = ent.getExt();
        int size = ent.getSize();
        switch(ext) {
            case "RGN":
                count++;
                System.out.println("RGN size " + size);
                assertThat("RGN size", size, new RangeMatcher(2704));
                break;
            case "TRE":
                count++;
                System.out.println("TRE size " + size);
                // Size varies depending on svn modified status
                assertThat("TRE size", size, new RangeMatcher(770, 2));
                break;
            case "LBL":
                count++;
                assertEquals("LBL size", 999, size);
                break;
        }
    }
    assertTrue("enough checks run", count >= 3);
}
Also used : RangeMatcher(func.lib.RangeMatcher) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry) Point(uk.me.parabola.imgfmt.app.trergn.Point) Test(org.junit.Test)

Example 5 with DirectoryEntry

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

the class GmapsuppTest method testBasic.

@Test
public void testBasic() throws IOException {
    File f = new File(GMAPSUPP_IMG);
    assertFalse("does not pre-exist", f.exists());
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", Args.TEST_RESOURCE_IMG + "63240001.img", Args.TEST_RESOURCE_IMG + "63240002.img");
    assertTrue("gmapsupp.img is created", f.exists());
    FileSystem fs = openFs(GMAPSUPP_IMG);
    DirectoryEntry entry = fs.lookup("63240001.TRE");
    assertNotNull("first file TRE", entry);
    assertEquals("first file TRE size", getFileSize(Args.TEST_RESOURCE_IMG + "63240001.img", "63240001.TRE"), entry.getSize());
    entry = fs.lookup("63240002.TRE");
    assertNotNull("second file TRE", entry);
    assertEquals("second file TRE size", getFileSize(Args.TEST_RESOURCE_IMG + "63240002.img", "63240002.TRE"), entry.getSize());
}
Also used : FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry) File(java.io.File) Test(org.junit.Test)

Aggregations

DirectoryEntry (uk.me.parabola.imgfmt.fs.DirectoryEntry)9 FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)8 Test (org.junit.Test)5 File (java.io.File)4 RangeMatcher (func.lib.RangeMatcher)2 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)2 Outputs (func.lib.Outputs)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)1 Point (uk.me.parabola.imgfmt.app.trergn.Point)1 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)1