Search in sources :

Example 1 with SRTFile

use of uk.me.parabola.imgfmt.app.srt.SRTFile 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 SRTFile

use of uk.me.parabola.imgfmt.app.srt.SRTFile in project mkgmap by openstreetmap.

the class FileCopier method writeSrtFile.

/**
 * Write the SRT file.
 *
 * @param imgFs The filesystem to create the SRT file in.
 * @throws FileNotWritableException If it cannot be created.
 */
private void writeSrtFile(FileSystem imgFs) throws FileNotWritableException {
    for (Map.Entry<Integer, Sort> ent : sortMap.entrySet()) {
        Sort sort = ent.getValue();
        int familyId = ent.getKey();
        if (sort.getId1() == 0 && sort.getId2() == 0)
            return;
        try {
            ImgChannel channel = imgFs.create(String.format("%08d.SRT", familyId));
            SRTFile srtFile = new SRTFile(channel);
            srtFile.setSort(sort);
            srtFile.write();
        // Do not close srtFile here
        } catch (FileExistsException e) {
            // well it shouldn't exist!
            log.error("could not create SRT file as it exists already");
            throw new FileNotWritableException("already existed", e);
        }
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) Sort(uk.me.parabola.imgfmt.app.srt.Sort) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 3 with SRTFile

use of uk.me.parabola.imgfmt.app.srt.SRTFile in project mkgmap by openstreetmap.

the class MdrBuilder method init.

/**
 * Create the mdr file and initialise.
 * It has a name that is based on the overview-mapname option, as does
 * the associated MDX file.
 *
 * @param args The command line arguments.
 */
public void init(CommandArgs args) {
    String name = args.get("overview-mapname", "osmmap");
    String outputDir = args.getOutputDir();
    outputName = Utils.joinPath(outputDir, name + "_mdr.img");
    ImgChannel mdrChan;
    try {
        // Create the .img file system/archive
        FileSystemParam params = new FileSystemParam();
        tmpName = File.createTempFile("mdr", null, new File(outputDir));
        tmpName.deleteOnExit();
        imgfs = ImgFS.createFs(tmpName.getPath(), params);
        // Create the MDR file within the .img
        mdrChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".MDR");
    } catch (IOException e) {
        throw new ExitException("Could not create global index file");
    }
    // Create the sort description
    Sort sort = SrtTextReader.sortForCodepage(args.getCodePage());
    // Set the options that we are using for the mdr.
    MdrConfig config = new MdrConfig();
    config.setHeaderLen(568);
    config.setWritable(true);
    config.setForDevice(false);
    config.setOutputDir(outputDir);
    config.setSort(sort);
    config.setIndexOptions(args);
    // Wrap the MDR channel with the MDRFile object
    mdrFile = new MDRFile(mdrChan, config);
    try {
        ImgChannel srtChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".SRT");
        SRTFile srtFile = new SRTFile(srtChan);
        srtFile.setSort(sort);
        srtFile.write();
    // Do not close srtFile here
    } catch (FileExistsException e) {
        throw new ExitException("Could not create SRT file within index file");
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MdrConfig(uk.me.parabola.imgfmt.app.mdr.MdrConfig) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) IOException(java.io.IOException) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) File(java.io.File) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Aggregations

SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)3 Sort (uk.me.parabola.imgfmt.app.srt.Sort)3 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)3 IOException (java.io.IOException)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)2 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)2 File (java.io.File)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)1 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)1 MDRFile (uk.me.parabola.imgfmt.app.mdr.MDRFile)1 MdrConfig (uk.me.parabola.imgfmt.app.mdr.MdrConfig)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1