From 7fbde8f81098f91bc1c5bbd6b16238ea0ef106ca Mon Sep 17 00:00:00 2001 From: Otavio Rodolfo Piske Date: Wed, 2 Oct 2024 13:34:26 -0300 Subject: [PATCH] CAMEL-21305: enable PDF conversions with stream cache --- .../camel/component/pdf/converter/PdfConverterLoader.java | 2 ++ .../camel/component/pdf/converter/PdfConverter.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java b/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java index 41f878e6320d0..26ff3d4223819 100644 --- a/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java +++ b/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java @@ -46,6 +46,8 @@ public void load(TypeConverterRegistry registry) throws TypeConverterLoaderExcep private void registerConverters(TypeConverterRegistry registry) { addTypeConverter(registry, org.apache.pdfbox.pdmodel.PDDocument.class, byte[].class, false, (type, exchange, value) -> getPdfConverter().convertToPDF((byte[]) value)); + addTypeConverter(registry, org.apache.pdfbox.pdmodel.PDDocument.class, java.io.InputStream.class, false, + (type, exchange, value) -> getPdfConverter().toPDDocument((java.io.InputStream) value)); } private static void addTypeConverter(TypeConverterRegistry registry, Class toType, Class fromType, boolean allowNull, SimpleTypeConverter.ConversionMethod method) { diff --git a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java index 4d236b512bafa..322b11176af0f 100644 --- a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java +++ b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java @@ -17,6 +17,8 @@ package org.apache.camel.component.pdf.converter; +import java.io.InputStream; + import org.apache.camel.Converter; import org.apache.pdfbox.Loader; import org.apache.pdfbox.pdmodel.PDDocument; @@ -28,4 +30,10 @@ public class PdfConverter { public PDDocument convertToPDF(byte[] bytes) throws Exception { return Loader.loadPDF(bytes); } + + @Converter + public PDDocument toPDDocument(InputStream stream) throws Exception { + final byte[] bytes = stream.readAllBytes(); + return convertToPDF(bytes); + } }