Internationalization and localization tools


Locale-Sensitive Java Method

java.lang.Runtime

public InputStream getLocalizedInputStream(InputStream in)

Internationalization (I18n) Method Overview

Creates what Sun's deprecated Javadocs refer to as a localized version of an input stream. This method takes an InputStream and returns another InputStream. The new InputStream assumes that all character data being read in are encoded in the native character encoding that corresponds to the default locale. As the binary data are read from the stream, the data are converted to characters by mapping each from the expected native encoding to Java's UTF-16 Unicode.

I18n Issues

If the InputStream generated by this method is attempting to read data that is not in the expected format, the data will likely become corrupted and exceptions might be thrown when the binary data doesn't properly map to UTF-16 code points as expected. It is recommended that developers instead call Java's InputStreamReader class and explicitly pass an encoding argument to ensure proper encoding conversion.

Suggested Replacement

java.io.InputStreamReader
public InputStreamReader(InputStream in,
    String charsetName)
   throws UnsupportedEncodingException

Instead of:

InputStream original;
//Instantiate the input stream here by
//reading in a file, etc. ...
Runtime rt = Runtime.getRuntime();
InputStream new = rt.getLocalizedInputStream(in);

Use:

InputStream in;
//instantiate the InputStream here ...
InputStreamReader reader = new InputStreamReader(
   in, getCorrectCharacterEncoding());

Locale-Sensitive Java Methods

 

Lingoport internationalization and localization services and software