Search in sources :

Example 1 with ImgChannel

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

the class SrtTextReader 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 = "in.txt";
    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 chan = new FileImgChannel(outfile, "rw");
    SRTFile sf = new SRTFile(chan);
    SrtTextReader tr = new SrtTextReader(infile);
    Sort sort1 = tr.getSort();
    sf.setSort(sort1);
    sf.write();
    sf.close();
    chan.close();
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) Sort(uk.me.parabola.imgfmt.app.srt.Sort) FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) CharacterCodingException(java.nio.charset.CharacterCodingException) ExitException(uk.me.parabola.imgfmt.ExitException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) IOException(java.io.IOException)

Example 2 with ImgChannel

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

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

the class StructureTest method init.

/**
 * Read in the file and open all the sections, leave references to them
 * in fields so that the other tests can check things.
 */
@BeforeClass
public static void init() throws FileNotFoundException {
    TestUtils.deleteOutputFiles();
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz");
    fs = ImgFS.openFs(Args.DEF_MAP_FILENAME);
    ImgChannel tre = fs.open(Args.DEF_MAP_ID + ".TRE", "r");
    treFile = new TREFileReader(tre);
    ImgChannel lbl = fs.open(Args.DEF_MAP_ID + ".LBL", "r");
    lblFile = new LBLFileReader(lbl);
    ImgChannel rgn = fs.open(Args.DEF_MAP_ID + ".RGN", "r");
    rgnFile = new RGNFileReader(rgn);
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) TREFileReader(uk.me.parabola.imgfmt.app.trergn.TREFileReader) RGNFileReader(uk.me.parabola.imgfmt.app.trergn.RGNFileReader) LBLFileReader(uk.me.parabola.imgfmt.app.lbl.LBLFileReader) BeforeClass(org.junit.BeforeClass)

Example 4 with ImgChannel

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

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

the class TYPFileTest method testWrite.

@Test
public void testWrite() throws Exception {
    TestUtils.registerFile("test.typ");
    FileSystemParam params = new FileSystemParam();
    try (FileSystem fs = ImgFS.createFs("test.typ", params)) {
        ImgChannel channel = fs.create("XXX.TYP");
        TYPFile typFile = new TYPFile(channel);
        assertNotNull("typ file is created", typFile);
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) Test(org.junit.Test)

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