Hi Gerd Trying to use display/src/test/ZipFile.java to reconstitute a tile .img from the constituents in a .gmap directory tree or extracted from a gmapsupp.img so I could run other display diagnostics I found it was broken, probably due to blocksize optimisation project. I attach a patch that gets it working again and has some comments about how it might be used.
Ticker
Index: src/test/ZipFile.java =================================================================== --- src/test/ZipFile.java (revision 553) +++ src/test/ZipFile.java (working copy) @@ -17,11 +17,15 @@ package test; import uk.me.parabola.imgfmt.FileSystemParam; +import uk.me.parabola.imgfmt.Sized; import uk.me.parabola.imgfmt.fs.FileSystem; import uk.me.parabola.imgfmt.fs.ImgChannel; import uk.me.parabola.imgfmt.sys.FileImgChannel; +import uk.me.parabola.imgfmt.sys.FileLink; import uk.me.parabola.imgfmt.sys.ImgFS; +import uk.me.parabola.imgfmt.Utils; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; @@ -31,6 +35,17 @@ /** * Combines several files into one .img file. * Kind of the opposite of ExtractFile. + * + * It can be used to reconstitute a tile .img file from the .LBL/.TRE/.RGN/.NET/.NOD etc files + * so that other display diagnostics can be run. + * eg, starting with just gmapsupp.img, extract all the components: + * $ doDisplay test.ExtractFile gmapsupp.img + * or, from a --gmapi directory, the components are in $family-name.gmap/Product1/${tilename} + * then, for either: + * $ doDisplay test.ZipFile ${tilename}.img ${tilename}.* + * now you can the various checks and displays in the tile, eg: + * $ doDisplay test.check.NodCheck ${tilename}.img + * * @author Steve Ratcliffe */ public class ZipFile { @@ -57,19 +72,51 @@ for (String name : inlist) { System.out.println("file " + name); File f = new File(name); - try (FileImgChannel fin = new FileImgChannel(name, "r"); - ImgChannel fout = fs.create(f.getName().toUpperCase())) - { - ByteBuffer buf = ByteBuffer.allocate(64*1024); - while (fin.read(buf) > 0) { - buf.flip(); - fout.write(buf); - buf.compact(); - } - } + FileCopier fc = new FileCopier(name); + ImgChannel fout = fs.create(f.getName().toUpperCase()); + ((FileLink)fout).link(fc, fc.file(fout)); } - fs.sync(); - fs.close(); + Utils.closeFile(fs); } } + +/** + * Copies file to composite .img. + * + * based on similar in mkgmap/builders/GmapsuppBuilder.java + */ +class FileCopier implements Sized { + private final String filename; + private long fileSize; + + public FileCopier(String filename) { + this.filename = filename; + File f = new File(filename); + fileSize = f.length(); + } + + Closeable file(ImgChannel fout) { + return () -> sync(fout); + } + + public void sync(ImgChannel fout) throws IOException { + try (ImgChannel fin = new FileImgChannel(filename, "r")) { + copyFile(fin, fout); + } + } + + private static void copyFile(ImgChannel fin, ImgChannel fout) throws IOException { + ByteBuffer buf = ByteBuffer.allocate(1024); + while (fin.read(buf) > 0) { + buf.flip(); + fout.write(buf); + buf.compact(); + } + } + + public long getSize() { + return fileSize; + } + +}
_______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev