use of com.teradata.jaqy.utils.CSVNameGen in project jaqy by Teradata.
the class CSVExporterFactory method getHandler.
@Override
public JaqyExporter getHandler(CommandLine cmdLine, JaqyInterpreter interpreter) throws Exception {
Charset charset = DEFAULT_CHARSET;
CSVFormat format = CSVFormat.DEFAULT;
HashMap<Integer, CSVExportInfo> exportInfoMap = new HashMap<Integer, CSVExportInfo>();
CSVNameGen nameGen = new CSVNameGen(DEFAULT_NAME_PATTERN);
Charset encoding = DEFAULT_CHARSET;
for (Option option : cmdLine.getOptions()) {
switch(option.getOpt().charAt(0)) {
case 'c':
{
charset = Charset.forName(option.getValue());
break;
}
case 'd':
{
char delimiter = CSVUtils.getChar(option.getValue());
if (delimiter == 0)
throw new IllegalArgumentException("invalid delimiter: " + option.getValue());
format = format.withDelimiter(delimiter);
break;
}
case 't':
{
format = CSVUtils.getFormat(option.getValue());
break;
}
case 'n':
{
String fmt = option.getValue();
nameGen = new CSVNameGen(fmt);
// now check if the name is a valid format.
if (fmt.equals(nameGen.getName(1)))
interpreter.error("Invalid name pattern: " + fmt);
break;
}
case 'e':
{
encoding = Charset.forName(option.getValue());
break;
}
case 'f':
{
int column = Integer.parseInt(option.getValue());
if (column < 1) {
interpreter.error("Column index cannot be smaller than 1.");
}
CSVExportInfo info = new CSVExportInfo(nameGen, encoding);
exportInfoMap.put(column, info);
break;
}
}
}
String[] args = cmdLine.getArgs();
if (args.length == 0)
throw new IllegalArgumentException("missing file name.");
Path file = interpreter.getPath(args[0]);
return new CSVExporter(file, charset, format, exportInfoMap);
}
Aggregations