public ReadCSV(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
super(builder, config, parent, child, context);
String separator = getConfigs().getString(config, "separator", ",");
if (separator.length() != 1) {
throw new MorphlineCompilationException("CSV separator must be one character only: " + separator, config);
}
this.separatorChar = separator.charAt(0);
this.columnNames = getConfigs().getStringList(config, "columns");
this.charset = getConfigs().getCharset(config, "charset", null);
this.ignoreFirstLine = getConfigs().getBoolean(config, "ignoreFirstLine", false);
this.trim = getConfigs().getBoolean(config, "trim", true);
this.quoteChar = getConfigs().getString(config, "quoteChar", "");
if (quoteChar.length() > 1) {
throw new MorphlineCompilationException(
"Quote character must not have a length of more than one character: " + quoteChar, config);
}
if (quoteChar.equals(String.valueOf(separatorChar))) {
throw new MorphlineCompilationException(
"Quote character must not be the same as separator: " + quoteChar, config);
}
this.commentPrefix = getConfigs().getString(config, "commentPrefix", "");
if (commentPrefix.length() > 1) {
throw new MorphlineCompilationException(
"Comment prefix must not have a length of more than one character: " + commentPrefix, config);
}
this.tokenizer = quoteChar.length() == 0 ?
new SimpleCSVTokenizer(separatorChar, trim, columnNames) :
new QuotedCSVTokenizer(separatorChar, trim, columnNames, quoteChar.charAt(0));