protected Parser createParser(Exchange exchange, Reader bodyReader) throws IOException {
if (isFixed()) {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), getDefinition());
InputStreamReader reader = new InputStreamReader(is, IOHelper.getCharsetName(exchange));
Parser parser = getParserFactory().newFixedLengthParser(reader, bodyReader);
if (allowShortLines) {
parser.setHandlingShortLines(true);
parser.setIgnoreParseWarnings(true);
}
if (ignoreExtraColumns) {
parser.setIgnoreExtraColumns(true);
parser.setIgnoreParseWarnings(true);
}
return parser;
} else {
if (ObjectHelper.isEmpty(getDefinition())) {
return getParserFactory().newDelimitedParser(bodyReader, delimiter, textQualifier);
} else {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), getDefinition());
InputStreamReader reader = new InputStreamReader(is, IOHelper.getCharsetName(exchange));
Parser parser = getParserFactory().newDelimitedParser(reader, bodyReader, delimiter, textQualifier, ignoreFirstRecord);
if (allowShortLines) {
parser.setHandlingShortLines(true);
parser.setIgnoreParseWarnings(true);
}
if (ignoreExtraColumns) {
parser.setIgnoreExtraColumns(true);
parser.setIgnoreParseWarnings(true);
}
return parser;
}
}
}