RED-4543 - In fileAttributesController, support ASCII and ISO as Encoding Type
- use encoding when import csv file
This commit is contained in:
parent
683253853e
commit
5c6cf4c728
@ -32,7 +32,7 @@ public interface FileAttributesConfigResource {
|
||||
|
||||
String UTF_ENCODING = "UTF-8";
|
||||
String ASCII_ENCODING = "ASCII";
|
||||
String ISO_ENCODING = "ISO-8601";
|
||||
String ISO_ENCODING = "ISO";
|
||||
|
||||
@ResponseBody
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
|
||||
@ -4,6 +4,7 @@ import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -46,6 +47,8 @@ import com.opencsv.exceptions.CsvException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static com.iqser.red.service.persistence.service.v1.api.resources.FileAttributesConfigResource.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@ -71,7 +74,7 @@ public class FileAttributesController implements FileAttributesResource {
|
||||
.filter(f -> !f.isSoftOrHardDeleted())
|
||||
.collect(Collectors.toMap(FileModel::getFilename, Function.identity()));
|
||||
|
||||
List<List<String>> rows = getCsvRecords(importCsvRequest.getCsvFile(), generalConfiguration.getDelimiter());
|
||||
List<List<String>> rows = getCsvRecords(importCsvRequest.getCsvFile(), generalConfiguration.getDelimiter(), generalConfiguration.getEncoding());
|
||||
|
||||
Iterator<List<String>> rowIterator = rows.iterator();
|
||||
|
||||
@ -138,7 +141,7 @@ public class FileAttributesController implements FileAttributesResource {
|
||||
|
||||
|
||||
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
|
||||
private List<List<String>> getCsvRecords(byte[] csv, String delimiter) {
|
||||
private List<List<String>> getCsvRecords(byte[] csv, String delimiter, String encoding) {
|
||||
|
||||
CSVParser parser = new CSVParserBuilder().withSeparator(delimiter.charAt(0)).build();
|
||||
|
||||
@ -154,5 +157,13 @@ public class FileAttributesController implements FileAttributesResource {
|
||||
return records;
|
||||
}
|
||||
|
||||
private Charset parseEncoding(String encoding) {
|
||||
if (ASCII_ENCODING.equalsIgnoreCase(encoding))
|
||||
return StandardCharsets.US_ASCII;
|
||||
if (ISO_ENCODING.equalsIgnoreCase(encoding))
|
||||
return StandardCharsets.ISO_8859_1;
|
||||
return StandardCharsets.UTF_8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user