Commit b43cfa9d authored by Matija Obreza's avatar Matija Obreza
Browse files

Allow for user-specified encoding

parent 5f26360e
......@@ -107,9 +107,10 @@ public class ValidatorController {
@RequestParam(name = "escapeChar", required = false, defaultValue = "\0") final Character escapeChar,
@RequestParam(name = "csvText", required = true) final String csvText, @RequestParam(name = "toCurrentTaxa", required = false) final Boolean toCurrentTaxa,
@RequestParam(name = "validateType", defaultValue = "") final String validateType, @RequestParam(name = "decimalMark", defaultValue = ".") final Character decimalMark,
@RequestParam(name = "encoding", defaultValue="UTF-16LE") final String encoding,
final HttpServletResponse response) throws IOException, ParseException, TaxonomyException {
processStringToCSV(separator, separatorOther, quoteChar, escapeChar, csvText, toCurrentTaxa, validateType, decimalMark, response);
processStringToCSV(separator, separatorOther, quoteChar, escapeChar, csvText, toCurrentTaxa, validateType, decimalMark, encoding, response);
}
/**
......@@ -133,6 +134,7 @@ public class ValidatorController {
@RequestParam(name = "escapeChar", required = false, defaultValue = "\0") final Character escapeChar,
@RequestParam(name = "csvText", required = true) final String csvText, @RequestParam(name = "toCurrentTaxa", required = false) final Boolean toCurrentTaxa,
@RequestParam(name = "validateType", defaultValue = "") final String validateType, @RequestParam(name = "decimalMark", defaultValue = ".") final Character decimalMark,
@RequestParam(name = "encoding", defaultValue="UTF-16LE") final String encoding,
final HttpServletResponse response) throws IOException, ParseException, TaxonomyException {
LOG.trace("Processing uploaded CSV string:\n{}", csvText);
......@@ -140,12 +142,12 @@ public class ValidatorController {
final List<String[]> rows = processService.process(new StringReader(StringUtils.defaultString(csvText, "")), separator == 'O' ? separatorOther : separator, quoteChar,
escapeChar, validateType, toCurrentTaxa, decimalMark);
response.setContentType("text/csv;charset=UTF-16LE");
response.setContentType("text/csv;charset=" + encoding);
response.addHeader("Content-Disposition", String.format("attachment; filename=\"validator-results.csv\""));
response.flushBuffer();
// Write CSV to the stream.
final OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(), "UTF-16LE");
final OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(), encoding);
try (CSVWriter csvWriter = new CSVWriter(osw, separator == 'O' ? separatorOther : separator, quoteChar, escapeChar, "\n")) {
csvWriter.writeAll(rows);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment