private Writer createWriter(Exchange exchange, Map<String, Object> firstRow, OutputStream stream) throws JDOMException, IOException {
if (isFixed()) {
Resource resource = getDefinition();
ObjectHelper.notNull(resource, "resource");
FixedWriterFactory factory = new FixedWriterFactory(new InputStreamReader(resource.getInputStream(), IOConverter.getCharsetName(exchange)));
return factory.createWriter(new OutputStreamWriter(stream, IOConverter.getCharsetName(exchange)));
} else {
Resource resource = getDefinition();
if (resource == null) {
DelimiterWriterFactory factory = new DelimiterWriterFactory(delimiter, textQualifier);
// add coulmns from the keys in the data map as the columns must be known