From f5c0cbb82bf22ccdb14fe2549a561e338909552b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 13 Aug 2024 11:15:43 +0200 Subject: [PATCH] feat: use the new FileSerde.writeAll and buffering for improved perf --- .../java/io/kestra/plugin/scripts/jvm/FileTransform.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugin-script/src/main/java/io/kestra/plugin/scripts/jvm/FileTransform.java b/plugin-script/src/main/java/io/kestra/plugin/scripts/jvm/FileTransform.java index 8c434b8..590bf4e 100644 --- a/plugin-script/src/main/java/io/kestra/plugin/scripts/jvm/FileTransform.java +++ b/plugin-script/src/main/java/io/kestra/plugin/scripts/jvm/FileTransform.java @@ -74,7 +74,7 @@ protected FileTransform.Output run(RunContext runContext, String engineName) thr ); try ( - OutputStream output = new FileOutputStream(tempFile); + var output = new BufferedWriter(new FileWriter(tempFile), FileSerde.BUFFER_SIZE) ) { if (from.startsWith("kestra://")) { try (BufferedReader inputStream = new BufferedReader(new InputStreamReader(runContext.storage().getFile(URI.create(from))))) { @@ -117,7 +117,7 @@ protected void finalize( RunContext runContext, Flux flowable, ScriptEngineService.CompiledScript scripts, - OutputStream output + Writer output ) throws IOException, ScriptException { Flux sequential; @@ -132,9 +132,7 @@ protected void finalize( .flatMap(this.convert(scripts)); } - Mono count = sequential - .doOnNext(throwConsumer(row -> FileSerde.write(output, row))) - .count(); + Mono count = FileSerde.writeAll(output, sequential); // metrics & finalize Long lineCount = count.block();