Common Locale Data Repository


Java locale data


CLDR


Viewing CLDR file

The CLDR files are all encoded using UTF-8 (see a later lecture). A program to display these is



import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.ResourceBundle;

public class UTFReader {

    public static ResourceBundle bundle;

    public static void main(String[] args) throws Exception {
	bundle = ResourceBundle.getBundle("UTFReader");

	if (args.length != 1) {
	    fatal("Usage");
	}
	
	new UTFReader(args);
    }
    
    public static void fatal(String errorType) {
	String errorMsg = bundle.getString(errorType);
	System.out.println("Fatal error: " + errorMsg);
	System.exit(1);
    }

    public UTFReader(String[] args) {
	FileInputStream fin = null;
	try {
	    fin = new FileInputStream(args[0]);
	} catch (FileNotFoundException e) {
	    fatal("FileNotFound");
	}
	
        BufferedReader in = null;
	try {
	     in = new BufferedReader(new InputStreamReader(fin, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
	    fatal("NoEncoding");
	}


	JFrame frame = new JFrame();
	JTextArea text = new JTextArea(20, 100);
	JScrollPane pane = new JScrollPane(text);

	frame.setSize(600,600);
	frame.getContentPane().add(pane, BorderLayout.CENTER);
	frame.setVisible(true);

	String s = null;
	try {
	    while ((s = in.readLine()) != null) {
		text.append(s + "\n");
	    }
	} catch (IOException e) {
	    // do nothing	    
	}
    }
}
wuth error messages in e.g. UTFReader.properties

Usage=Usage: java UTFReader <filename>
FileNotFound: File not found
NoEncoding: Cannot decode file format

On my system, the following terminal will also allow UTF fonts to be viewed


LANG=en_GB.utf8 xterm -fn '-bitstream-bitstream cyberbit-medium-r-normal--0-0-0-0-c-0-iso10646-1'


Jan Newmarch <jan@newmarch.name>
Last modified: Fri Mar 11 16:34:42 EST 2005
Copyright © Jan Newmarch, Monash University, 2007
Creative Commons License This work is licensed under a Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.