Wednesday, September 15, 2010

Encoding OutputStreams

This is a simple snippet of how to encode a simple output:

OutputStream outStream; // stream to where xml is being sent

BufferedWriter out =
new BufferedWriter(
new OutputStreamWriter(
outStream,
Charset.forName("LATIN1")));

out.write(xmlAsString);
out.flush();

Charsets can easily retrieved as follows:

SortedMap av= Charset.availableCharsets();
for (String cs:av.keySet()) {
System.out.println(cs+", "+Charset.forName(cs).name());
}

No comments: