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();
}
}
}
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();
}
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();
}
}
}
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();
}
}
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();
}
}
Aggregations