Генерация CSV занимает больше времени при работе с большими данными ⇐ JAVA
Генерация CSV занимает больше времени при работе с большими данными
Controller
@GetMapping(value = "/result", produces = "text/csv") public ResponseEntity getResult(@RequestParam String id) { final List empList = List.of(emp1, emp2); final InputStreamResource inputStreamResource = new InputStreamResource(validationResultsToCSV(empList)); return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + "result.csv") .contentType(MediaType.parseMediaType("text/csv")) .body(inputStreamResource); } public ByteArrayInputStream validationResultsToCSV(final List empList) { final CSVFormat format = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.MINIMAL); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); final CSVPrinter csvPrinter = new CSVPrinter(new PrintWriter(out), format)) { final List header = new ArrayList(); header.addAll(List.of("id", "emp name")); csvPrinter.printRecord(header); for (final Employee emp : entity.getCoverageStaging()) { final List data = new ArrayList(); data.addAll(Arrays.asList(emp.getId(), emp.getName())); csvPrinter.printRecord(data); } csvPrinter.flush(); return new ByteArrayInputStream(out.toByteArray()); } catch (IOException e) { throw new RuntimeException("Fail to import data to CSV file: " + e.getMessage()); } } This code is taking around 2-3 mins to generate csv for 50k records which seems long. is there any alternate and fast way to deal with this kind of case?
Источник: https://stackoverflow.com/questions/781 ... large-data
Controller
@GetMapping(value = "/result", produces = "text/csv") public ResponseEntity getResult(@RequestParam String id) { final List empList = List.of(emp1, emp2); final InputStreamResource inputStreamResource = new InputStreamResource(validationResultsToCSV(empList)); return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + "result.csv") .contentType(MediaType.parseMediaType("text/csv")) .body(inputStreamResource); } public ByteArrayInputStream validationResultsToCSV(final List empList) { final CSVFormat format = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.MINIMAL); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); final CSVPrinter csvPrinter = new CSVPrinter(new PrintWriter(out), format)) { final List header = new ArrayList(); header.addAll(List.of("id", "emp name")); csvPrinter.printRecord(header); for (final Employee emp : entity.getCoverageStaging()) { final List data = new ArrayList(); data.addAll(Arrays.asList(emp.getId(), emp.getName())); csvPrinter.printRecord(data); } csvPrinter.flush(); return new ByteArrayInputStream(out.toByteArray()); } catch (IOException e) { throw new RuntimeException("Fail to import data to CSV file: " + e.getMessage()); } } This code is taking around 2-3 mins to generate csv for 50k records which seems long. is there any alternate and fast way to deal with this kind of case?
Источник: https://stackoverflow.com/questions/781 ... large-data
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Неожиданные результаты при работе с очень большими целыми числами на интерпретируемых языках.
Anonymous » » в форуме Php - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Каким должно быть тело ответа HTTP 201 при ответе на запрос POST с большими данными?
Anonymous » » в форуме Python - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Каким должно быть тело ответа HTTP 201 при ответе на запрос POST с большими данными?
Anonymous » » в форуме Python - 0 Ответы
- 28 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Каким должно быть тело ответа HTTP 201 при ответе на запрос POST с большими данными?
Anonymous » » в форуме Python - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-