Search in sources :

Example 1 with FileSystem

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

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

the class Base method openFs.

protected FileSystem openFs(String filename) throws FileNotFoundException {
    FileSystem fs = ImgFS.openFs(filename);
    TestUtils.registerFile(fs);
    return fs;
}
Also used : FileSystem(uk.me.parabola.imgfmt.fs.FileSystem)

Example 3 with FileSystem

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

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

the class GmapsuppTest method testImplicitCodePageIndex.

/**
 * If no code page is given for the index, it is taken from the input files.
 */
@Test
public void testImplicitCodePageIndex() throws IOException {
    TestUtils.registerFile("osmmap_mdr.img", "osmmap.img", "osmmap.tbd", "osmmap.mdx");
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--code-page=1256", Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz");
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--index", "63240001.img");
    assertFalse(new File("osmmap_mdr.img").exists());
    FileSystem fs = openFs(GMAPSUPP_IMG);
    ImgChannel r = fs.open("00006324.MDR", "r");
    ByteBuffer buf = ByteBuffer.allocate(1024);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    r.read(buf);
    assertEquals(1256, buf.getChar(0x15));
    assertEquals(0x010009, buf.getInt(0x17));
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with FileSystem

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

the class GmapsuppTest method getMpsFile.

private MpsFileReader getMpsFile() throws IOException {
    FileSystem fs = openFs(GMAPSUPP_IMG);
    MpsFileReader reader = new MpsFileReader(fs.open("MAKEGMAP.MPS", "r"), 0);
    TestUtils.registerFile(reader);
    return reader;
}
Also used : FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) 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