smartrics/RestFixture — Issue #13: Better charset handling
Author: knutz3n
Created: 2012-02-23 16:10:40+00:00
State: open

The method `getInputStreamFromString` should support an explicit charset and not rely on the system platform defaults when doing `string.getBytes`.
Currently, XML parsing fails with a SAXException: "Invalid byte 2 of 2-byte UTF-8 sequence" when trying to parse UTF-8 encoded XML on Windows platform with Cp1252 as default charset.

The following changes in [Tools.java](https://github.com/smartrics/RestFixture/blob/master/src/main/java/smartrics/rest/fitnesse/fixture/support/Tools.java#L255) fixes the problem, but might cause problems when response is not UTF-8.

- byte[] byteArray = string.getBytes();
- return new ByteArrayInputStream(byteArray);
+ try {
+ byte[] byteArray = string.getBytes("UTF-8");
+ return new ByteArrayInputStream(byteArray);
+ } catch(UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }