Question

I have a Fixed Length stream. I want to set encoding to Windows-1252 or latin1.

How can I do that?

Via XML would be better, but if code is the only way, it is ok too.

Was it helpful?

Solution

Character encoding is controlled external to the BeanIO library using the basic Java I/O APIs. Here's a quick and dirty example showing the setup for writing:

Charset charset = Charset.forName("ISO-8859-1"); // ISO Latin Alphabet No. 1
OutputStream ostream = new ByteArrayOutputStream(); // or other OutputStream
Writer writer = new OutputStreamWriter(ostream, charset);

BeanWriter beanWriter = streamFactory.createWriter(nameOfMappedStream, writer);

// write beans here...

writer.flush();

Reading should be similar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top