From 51536393a4a812e781bc687f37a688e02bdef104 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Wed, 19 Nov 2025 12:52:06 +0100 Subject: [PATCH] chore(components): docling stream closure --- .../camel/component/docling/DoclingProducer.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java b/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java index d5bbe64cab547..3306dec0e39d5 100644 --- a/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java +++ b/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; @@ -650,10 +651,6 @@ private List extractDocumentList(Exchange exchange) { + ". Expected List, List, String[], File[], or directory path"); } - private String convertUsingDoclingServe(String inputPath, String outputFormat) throws Exception { - return convertUsingDoclingServe(inputPath, outputFormat, null); - } - private String convertUsingDoclingServe(String inputPath, String outputFormat, Exchange exchange) throws Exception { // Check for header override boolean useAsync = configuration.isUseAsyncMode(); @@ -902,10 +899,9 @@ private String getOutputFileExtension(String outputFormat) { } private void deleteDirectory(Path directory) { - try { - if (Files.exists(directory)) { - Files.walk(directory) - .sorted((a, b) -> b.compareTo(a)) // Delete files before directories + if (Files.exists(directory)) { + try (Stream paths = Files.walk(directory)) { + paths.sorted((a, b) -> b.compareTo(a)) // Delete files before directories .forEach(path -> { try { Files.delete(path); @@ -913,9 +909,9 @@ private void deleteDirectory(Path directory) { LOG.warn("Failed to delete temporary file: {}", path, e); } }); + } catch (IOException e) { + LOG.warn("Failed to clean up temporary directory: {}", directory, e); } - } catch (IOException e) { - LOG.warn("Failed to clean up temporary directory: {}", directory, e); } }