Search in sources :

Example 1 with TypTextReader

use of uk.me.parabola.mkgmap.typ.TypTextReader in project mkgmap by openstreetmap.

the class TypCompiler method compile.

/**
 * Read and compile a TYP file, returning the compiled form.
 *
 * @param filename The input filename.
 * @param charset The character set to use to read this file. We should have already determined
 * that this character set is valid and can be used to read the file.
 * @param sort The sort information from command line options, used for the output code page
 * only. If null, then the code page set by CodePage in the typ.txt file will be used.
 *
 * @return The compiled form as a data structure.
 * @throws FileNotFoundException If the file doesn't exist.
 * @throws SyntaxException All user correctable problems in the input file.
 */
private TypData compile(String filename, String charset, Sort sort) throws FileNotFoundException, SyntaxException {
    TypTextReader tr = new TypTextReader();
    TypData data = tr.getData();
    data.setSort(sort);
    try {
        Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), charset));
        try {
            tr.read(filename, r);
        } finally {
            Utils.closeFile(r);
        }
    } catch (UnsupportedEncodingException e) {
        // Not likely to happen as we should have already used this character set!
        throw new MapFailedException("Unsupported character set", e);
    }
    return tr.getData();
}
Also used : InputStreamReader(java.io.InputStreamReader) TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) BufferedReader(java.io.BufferedReader) TypTextReader(uk.me.parabola.mkgmap.typ.TypTextReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TypTextReader(uk.me.parabola.mkgmap.typ.TypTextReader) FileInputStream(java.io.FileInputStream)

Aggregations

BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 TypData (uk.me.parabola.imgfmt.app.typ.TypData)1 TypTextReader (uk.me.parabola.mkgmap.typ.TypTextReader)1