private Writer createWriter(Exchange exchange, Map<String, Object> firstRow, OutputStream stream) throws JDOMException, IOException {
if (isFixed()) {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), getDefinition());
InputStreamReader reader = new InputStreamReader(is, IOHelper.getCharsetName(exchange));
FixedWriterFactory factory = new FixedWriterFactory(reader);
return factory.createWriter(new OutputStreamWriter(stream, IOHelper.getCharsetName(exchange)));
} else {
if (getDefinition() == null) {
DelimiterWriterFactory factory = new DelimiterWriterFactory(delimiter, textQualifier);
// add columns from the keys in the data map as the columns must be known
for (String key : firstRow.keySet()) {