Search in sources :

Example 1 with FileImgChannel

use of uk.me.parabola.imgfmt.sys.FileImgChannel in project mkgmap by openstreetmap.

the class TypCompiler method writeTyp.

/**
 * Write the type file out from the compiled form to the given name.
 */
private void writeTyp(TypData data, File file) throws IOException {
    try (FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ)) {
        channel.truncate(0);
        FileImgChannel w = new FileImgChannel(channel);
        try (TYPFile typ = new TYPFile(w)) {
            typ.setData(data);
            typ.write();
        }
    }
}
Also used : TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) FileChannel(java.nio.channels.FileChannel) FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel)

Example 2 with FileImgChannel

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

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

use of uk.me.parabola.imgfmt.sys.FileImgChannel in project mkgmap by openstreetmap.

the class TypTextReaderTest method testFromFile.

/**
 * Basic test, reading from a file using most features.
 */
@Test
public void testFromFile() throws IOException, InterruptedException {
    Reader r = new BufferedReader(new FileReader("test/resources/typ/test.txt"));
    tr = new TypTextReader();
    tr.read("test.typ", r);
    TestUtils.registerFile("ts__test.typ");
    RandomAccessFile raf = new RandomAccessFile("ts__test.typ", "rw");
    FileChannel channel = raf.getChannel();
    channel.truncate(0);
    try (FileImgChannel w = new FileImgChannel(channel);
        TYPFile typ = new TYPFile(w)) {
        typ.setData(tr.getData());
        typ.write();
    } finally {
        raf.close();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) FileChannel(java.nio.channels.FileChannel) BufferedReader(java.io.BufferedReader) SrtTextReader(uk.me.parabola.mkgmap.srt.SrtTextReader) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) Test(org.junit.Test)

Example 5 with FileImgChannel

use of uk.me.parabola.imgfmt.sys.FileImgChannel 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)

Aggregations

FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)5 IOException (java.io.IOException)3 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)3 FileChannel (java.nio.channels.FileChannel)2 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 RandomAccessFile (java.io.RandomAccessFile)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 Test (org.junit.Test)1 ExitException (uk.me.parabola.imgfmt.ExitException)1 BufferedImgFileReader (uk.me.parabola.imgfmt.app.BufferedImgFileReader)1 SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)1 Sort (uk.me.parabola.imgfmt.app.srt.Sort)1 DirectoryEntry (uk.me.parabola.imgfmt.fs.DirectoryEntry)1 FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1