Search in sources :

Example 11 with ImgChannel

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

the class GmapsuppTest method testWithTwoIndexes.

@Test
public void testWithTwoIndexes() throws IOException {
    TestUtils.registerFile("osmmap_mdr.img", "osmmap.img", "osmmap.tbd", "osmmap.mdx");
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--index", "--tdbfile", "--latin1", "--family-id=101", "--product-id=1", "--family-name=tst family1", "--series-name=tst series1", Args.TEST_RESOURCE_IMG + "63240001.img", Args.TEST_RESOURCE_IMG + "63240002.img");
    assertTrue(new File("osmmap_mdr.img").exists());
    // All we are doing here is checking that the file was created and that it is
    // not completely empty.
    FileSystem fs = openFs(GMAPSUPP_IMG);
    ImgChannel r = fs.open("00000101.MDR", "r");
    r.position(2);
    ByteBuffer buf = ByteBuffer.allocate(1024);
    int read = r.read(buf);
    assertEquals(1024, read);
    buf.flip();
    byte[] b = new byte[3];
    buf.get(b, 0, 3);
    assertEquals('G', b[0]);
}
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 12 with ImgChannel

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

the class GmapsuppTest method testTwoFamilyIndex.

/**
 * If there are files in two (or more) families then there should be a MDR and SRT for each.
 */
@Test
public void testTwoFamilyIndex() throws IOException {
    TestUtils.registerFile("osmmap_mdr.img", "osmmap.img", "osmmap.tbd", "osmmap.mdx");
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--index", "--latin1", "--family-id=101", "--product-id=1", "--family-name=tst family1", "--series-name=tst series1", Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz", "--family-id=202", "--family-name=tst family2", "--series-name=tst series2", Args.TEST_RESOURCE_OSM + "uk-test-2.osm.gz");
    assertFalse(new File("osmmap_mdr.img").exists());
    // All we are doing here is checking that the file was created and that it is
    // not completely empty.
    FileSystem fs = openFs(GMAPSUPP_IMG);
    ImgChannel r = fs.open("00000101.MDR", "r");
    r.position(2);
    ByteBuffer buf = ByteBuffer.allocate(1024);
    int read = r.read(buf);
    assertEquals(1024, read);
    fs = openFs(GMAPSUPP_IMG);
    r = fs.open("00000202.MDR", "r");
    r.position(2);
    buf.clear();
    read = r.read(buf);
    assertEquals(1024, read);
    r = fs.open("00000202.SRT", "r");
    buf = ByteBuffer.allocate(512);
    read = r.read(buf);
    assertEquals(512, read);
    r = fs.open("00000101.SRT", "r");
    buf.clear();
    read = r.read(buf);
    assertEquals(512, read);
}
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 13 with ImgChannel

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

the class GmapsuppTest method testWithIndex.

@Test
public void testWithIndex() throws IOException {
    new File("osmmap_mdr.img").delete();
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--index", "--latin1", "--family-id=101", "--product-id=1", "--family-name=tst family1", "--series-name=tst series1", Args.TEST_RESOURCE_IMG + "63240001.img", Args.TEST_RESOURCE_IMG + "63240002.img");
    assertFalse(new File("osmmap_mdr.img").exists());
    // All we are doing here is checking that the file was created and that it is
    // not completely empty.
    FileSystem fs = openFs(GMAPSUPP_IMG);
    ImgChannel r = fs.open("00000101.MDR", "r");
    r.position(2);
    ByteBuffer buf = ByteBuffer.allocate(1024);
    int read = r.read(buf);
    assertEquals(1024, read);
    buf.flip();
    byte[] b = new byte[3];
    buf.get(b, 0, 3);
    assertEquals('G', b[0]);
}
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 14 with ImgChannel

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

the class FileInfo method typInfo.

/**
 * Read information from the TYP file that we might need when combining it with other files.
 * @param filename The name of the file.
 * @param info The information will be stored here.
 */
private static void typInfo(String filename, FileInfo info) {
    try (ImgChannel chan = new FileImgChannel(filename, "r");
        BufferedImgFileReader fr = new BufferedImgFileReader(chan)) {
        fr.position(0x15);
        info.setCodePage(fr.getChar());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) IOException(java.io.IOException) FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader)

Example 15 with ImgChannel

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

the class FileInfo method treInfo.

/**
 * Obtain the information that we need from the TRE section.
 * @param imgFs The filesystem
 * @param ent The filename within the filesystem of the TRE file.
 * @param info This is where the information will be saved.
 * @throws FileNotFoundException If the file is not found in the filesystem.
 */
private static void treInfo(FileSystem imgFs, DirectoryEntry ent, FileInfo info) throws FileNotFoundException {
    try (ImgChannel treChan = imgFs.open(ent.getFullName(), "r");
        TREFileReader treFile = new TREFileReader(treChan)) {
        info.setBounds(treFile.getBounds());
        info.setLicenceInfo(treFile.getMapInfo(info.getCodePage()));
        info.setHexname(((TREHeader) treFile.getHeader()).getMapId());
    } catch (FileNotFoundException e) {
        throw e;
    } catch (IOException e) {
        throw new FileNotFoundException();
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) TREFileReader(uk.me.parabola.imgfmt.app.trergn.TREFileReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

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