diff --git a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/detector/FileContentDetector.java b/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/detector/FileContentDetector.java deleted file mode 100644 index 2ca2ad28b60..00000000000 --- a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/detector/FileContentDetector.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.detector; - -import java.nio.file.Files; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FilenameUtils; -import org.apache.fineract.infrastructure.contentstore.exception.ContentDetectorException; -import org.springframework.stereotype.Component; - -@Slf4j -@RequiredArgsConstructor -@Component -public final class FileContentDetector implements ContentDetector { - - @Override - public ContentDetectorContext detect(ContentDetectorContext ctx) { - try { - final var mimeType = Files.probeContentType(java.nio.file.Path.of(ctx.getFileName())); - final var format = FilenameUtils.getExtension(ctx.getFileName()); - - return ctx.clone(mimeType, "." + format, format); - } catch (Exception e) { - throw new ContentDetectorException(e); - } - } -} diff --git a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/exception/ContentPathSanitizerException.java b/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/exception/ContentPathSanitizerException.java deleted file mode 100644 index 56f14934905..00000000000 --- a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/exception/ContentPathSanitizerException.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.exception; - -import org.apache.fineract.infrastructure.core.exception.AbstractPlatformException; - -public class ContentPathSanitizerException extends AbstractPlatformException { - - public ContentPathSanitizerException(String message) { - super("error.msg.content.sanitizer", message); - } -} diff --git a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/GzipDecoderContentProcessor.java b/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/GzipDecoderContentProcessor.java deleted file mode 100644 index 7166eced297..00000000000 --- a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/GzipDecoderContentProcessor.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.processor; - -import static java.util.Objects.requireNonNullElse; - -import java.util.zip.GZIPInputStream; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.contentstore.util.ContentPipe; -import org.apache.fineract.infrastructure.core.config.FineractProperties; -import org.springframework.stereotype.Component; - -@Slf4j -@RequiredArgsConstructor -@Component -public class GzipDecoderContentProcessor implements ContentProcessor { - - private static final String GZIP_DECODE_PREFIX = "gzip.decode."; - - public static final String GZIP_DECODE_PARAM_BUFFER_SIZE = GZIP_DECODE_PREFIX + "buffer-size"; - - private final ContentPipe pipe; - private final FineractProperties properties; - - @Override - public ContentProcessorContext process(final ContentProcessorContext ctx) { - final Integer bufferSize = ctx.getParameter(GZIP_DECODE_PARAM_BUFFER_SIZE, Integer.class, - requireNonNullElse(properties.getContent().getDefaultBufferSize(), 8192)); - - final var pipedInputStream = pipe.pipe(ctx.getInputStream(), (in, out) -> { - pipe.write(new GZIPInputStream(in), out, new byte[bufferSize]); - }); - - return ctx.clone(pipedInputStream); - } -} diff --git a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/GzipEncoderContentProcessor.java b/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/GzipEncoderContentProcessor.java deleted file mode 100644 index 148352485da..00000000000 --- a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/GzipEncoderContentProcessor.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.processor; - -import static java.util.Objects.requireNonNullElse; - -import java.util.zip.GZIPOutputStream; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.contentstore.util.ContentPipe; -import org.apache.fineract.infrastructure.core.config.FineractProperties; -import org.springframework.stereotype.Component; - -@Slf4j -@RequiredArgsConstructor -@Component -public class GzipEncoderContentProcessor implements ContentProcessor { - - private static final String GZIP_ENCODE_PREFIX = "gzip.encode."; - - public static final String GZIP_ENCODE_PARAM_BUFFER_SIZE = GZIP_ENCODE_PREFIX + "buffer-size"; - - private final ContentPipe pipe; - private final FineractProperties properties; - - @Override - public ContentProcessorContext process(final ContentProcessorContext ctx) { - final Integer bufferSize = ctx.getParameter(GZIP_ENCODE_PARAM_BUFFER_SIZE, Integer.class, - requireNonNullElse(properties.getContent().getDefaultBufferSize(), 8192)); - - final var pipedInputStream = pipe.pipe(ctx.getInputStream(), (in, out) -> { - pipe.write(in, new GZIPOutputStream(out), new byte[bufferSize]); - }); - - return ctx.clone(pipedInputStream); - } -} diff --git a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/SizeContentProcessor.java b/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/SizeContentProcessor.java deleted file mode 100644 index 3c7b9575fb2..00000000000 --- a/fineract-document/src/main/java/org/apache/fineract/infrastructure/contentstore/processor/SizeContentProcessor.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.processor; - -import java.io.FilterInputStream; -import java.io.IOException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -@Slf4j -@RequiredArgsConstructor -@Component -public class SizeContentProcessor implements ContentProcessor { - - private static final String SIZE_PREFIX = "size."; - - public static final String SIZE_RESULT_VALUE = SIZE_PREFIX + "result.value"; - - @Override - public ContentProcessorContext process(ContentProcessorContext ctx) { - return ctx.clone(new ByteCountingInputStream(ctx)); - } - - private static final class ByteCountingInputStream extends FilterInputStream { - - private final ContentProcessorContext ctx; - private long byteCount = 0; - - ByteCountingInputStream(ContentProcessorContext ctx) { - super(ctx.getInputStream()); - this.ctx = ctx; - } - - @Override - public int read() throws IOException { - int data = in.read(); - - if (data != -1) { - byteCount++; - } - - return data; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - int count = in.read(b, off, len); - - if (count != -1) { - byteCount += count; - } - - return count; - } - - @Override - public void close() throws IOException { - ctx.setResult(SIZE_RESULT_VALUE, byteCount); - - super.close(); - } - } -} diff --git a/fineract-document/src/test/java/org/apache/fineract/infrastructure/contentstore/detector/FileContentDetectorTest.java b/fineract-document/src/test/java/org/apache/fineract/infrastructure/contentstore/detector/FileContentDetectorTest.java deleted file mode 100644 index 1c683082831..00000000000 --- a/fineract-document/src/test/java/org/apache/fineract/infrastructure/contentstore/detector/FileContentDetectorTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.detector; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.TestConfiguration; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; - -@Slf4j -@SpringBootTest -@ContextConfiguration(classes = TestConfiguration.class) -class FileContentDetectorTest { - - @Autowired - private FileContentDetector fileContentDetector; - - @Test - void detectByFileName() { - var ctx = fileContentDetector.detect(ContentDetectorContext.builder().fileName("test.png").build()); - - assertEquals("png", ctx.getFormat()); - assertEquals(".png", ctx.getExtension()); - assertEquals("image/png", ctx.getMimeType()); - - ctx = fileContentDetector.detect(ContentDetectorContext.builder().fileName("test.jpg").build()); - - assertEquals("jpg", ctx.getFormat()); - assertEquals(".jpg", ctx.getExtension()); - assertEquals("image/jpeg", ctx.getMimeType()); - } -} diff --git a/fineract-document/src/test/java/org/apache/fineract/infrastructure/contentstore/processor/ContentProcessorTest.java b/fineract-document/src/test/java/org/apache/fineract/infrastructure/contentstore/processor/ContentProcessorTest.java deleted file mode 100644 index ba9d8da1833..00000000000 --- a/fineract-document/src/test/java/org/apache/fineract/infrastructure/contentstore/processor/ContentProcessorTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.contentstore.processor; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.fineract.infrastructure.contentstore.processor.DataUrlDecoderContentProcessor.DATA_URL_DECODE_RESULT_CONTENT_TYPE; -import static org.apache.fineract.infrastructure.contentstore.processor.DataUrlEncoderContentProcessor.DATA_URL_ENCODE_PARAM_CONTENT_TYPE; -import static org.apache.fineract.infrastructure.contentstore.processor.DataUrlEncoderContentProcessor.DATA_URL_ENCODE_PARAM_ENCODING; -import static org.apache.fineract.infrastructure.contentstore.processor.ImageResizeContentProcessor.IMAGE_RESIZE_PARAM_FORMAT; -import static org.apache.fineract.infrastructure.contentstore.processor.ImageResizeContentProcessor.IMAGE_RESIZE_PARAM_MAX_HEIGHT; -import static org.apache.fineract.infrastructure.contentstore.processor.ImageResizeContentProcessor.IMAGE_RESIZE_PARAM_MAX_WIDTH; -import static org.apache.fineract.infrastructure.contentstore.processor.SizeContentProcessor.SIZE_RESULT_VALUE; - -import java.io.ByteArrayInputStream; -import java.nio.file.Files; -import java.util.Map; -import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.TestConfiguration; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; - -@Slf4j -@SpringBootTest -@ContextConfiguration(classes = TestConfiguration.class) -class ContentProcessorTest { - - @Autowired - private Base64EncoderContentProcessor base64EncoderContentProcessor; - - @Autowired - private Base64DecoderContentProcessor base64DecoderContentProcessor; - - @Autowired - private DataUrlEncoderContentProcessor dataUrlEncoderContentProcessor; - - @Autowired - private DataUrlDecoderContentProcessor dataUrlDecoderContentProcessor; - - @Autowired - private ImageResizeContentProcessor imageResizeContentProcessor; - - @Autowired - private SizeContentProcessor sizeContentProcessor; - - static final byte[] DATA_BASE64 = """ - iVBORw0KGgoAAAANSUhEUgAAANwAAADcCAYAAAAbWs+BAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ - bWFnZVJlYWR5ccllPAAAAodJREFUeNrs3NFtg0AQRVGPRRNWyoCeUhM9LWWkjUw6iIQyCRvmnAKQ - F3S1/nqRmQ/gbzy9AhAcCA4QHAgOEBwIDgQHCA4EBwgOBAeCAwQHggMEB4IDBAeCg/tbvAJuJaJ2 - pCcz3HDgLyUgOBAcCA4QHAgOEBwIDhAcCA4EBwgOBAcIDgQHggMEB4IDTmm3aRKxlW5erOva6v2N - sUft96jdIMndDQcIDgQHggMEB4IDBAeCA8EBggPBAYIDwQGCA8GB4ADBgeAAwcHFpt806bZBMvvv - 27b32g2SzOgUnBsOBAeCAwQHggMEB4IDwQGCA8EBggPBgeAAwYHgAMGB4ADBgeCggcjM2gcWb5BU - m30zpNt5j+Mofd4Y+9QbKW44EBwIDhAcCA4QHAgOBAcIDgQHCA4EB4IDBAeCAwQHggMEB4KDBpZu - B67e0Oi2GdJtE8YNB4IDBAeCA8EBggPBAYIDwQGCA8GB4ADBgeAAwYHgQHCA4EBwwGmRmbUPjLfa - Bz5erT6IzZCfGWMPNxwgOBAcCA4QHAgOEBwIDgQHCA4EBwgOBAeC8wpAcCA4QHAgOEBwcKl/sGlS - 7eWr31jmsGkCCA4EB4IDBAeCAwQHggPBAYIDwQGCA8EBggPBgeAAwYHgAMHBtco3Tcp/4PQbKdV6 - ba7MvkHihgPBAYIDwYHgAMGB4ADBgeAAwYHgQHCA4EBwgOBAcCA4QHAgOOC06TdNyg8cz+IDd9sg - +QjZuOFAcIDgQHAgOEBwIDhAcCA4EBwgOBAcIDgQHCA4EBwIDhAcCA74xtLtwJmfNjlww4HgAMGB - 4ADBgeBAcIDgQHCA4EBwgOBAcCA4QHAgOEBwIDgQHPB7vgQYAPVcRHV5+lfgAAAAAElFTkSuQmCC""".getBytes(UTF_8); - - private static final byte[] DATA_URL = """ - data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAADcCAYAAAAbWs+BAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ - bWFnZVJlYWR5ccllPAAAAodJREFUeNrs3NFtg0AQRVGPRRNWyoCeUhM9LWWkjUw6iIQyCRvmnAKQ - F3S1/nqRmQ/gbzy9AhAcCA4QHAgOEBwIDgQHCA4EBwgOBAeCAwQHggMEB4IDBAeCg/tbvAJuJaJ2 - pCcz3HDgLyUgOBAcCA4QHAgOEBwIDhAcCA4EBwgOBAcIDgQHggMEB4IDTmm3aRKxlW5erOva6v2N - sUft96jdIMndDQcIDgQHggMEB4IDBAeCA8EBggPBAYIDwQGCA8GB4ADBgeAAwcHFpt806bZBMvvv - 27b32g2SzOgUnBsOBAeCAwQHggMEB4IDwQGCA8EBggPBgeAAwYHgAMGB4ADBgeCggcjM2gcWb5BU - m30zpNt5j+Mofd4Y+9QbKW44EBwIDhAcCA4QHAgOBAcIDgQHCA4EB4IDBAeCAwQHggMEB4KDBpZu - B67e0Oi2GdJtE8YNB4IDBAeCA8EBggPBAYIDwQGCA8GB4ADBgeAAwYHgQHCA4EBwwGmRmbUPjLfa - Bz5erT6IzZCfGWMPNxwgOBAcCA4QHAgOEBwIDgQHCA4EBwgOBAeC8wpAcCA4QHAgOEBwcKl/sGlS - 7eWr31jmsGkCCA4EB4IDBAeCAwQHggPBAYIDwQGCA8EBggPBgeAAwYHgAMHBtco3Tcp/4PQbKdV6 - ba7MvkHihgPBAYIDwYHgAMGB4ADBgeAAwYHgQHCA4EBwgOBAcCA4QHAgOOC06TdNyg8cz+IDd9sg - +QjZuOFAcIDgQHAgOEBwIDhAcCA4EBwgOBAcIDgQHCA4EBwIDhAcCA74xtLtwJmfNjlww4HgAMGB - 4ADBgeBAcIDgQHCA4EBwgOBAcCA4QHAgOEBwIDgQHPB7vgQYAPVcRHV5+lfgAAAAAElFTkSuQmCC""".getBytes(UTF_8); - - @Test - void process() { - - final var ctx = sizeContentProcessor.then(base64DecoderContentProcessor).process(new ByteArrayInputStream(DATA_BASE64)); - - write(ctx, "process.png"); - - String type = ctx.getResult(DATA_URL_DECODE_RESULT_CONTENT_TYPE, String.class); - Long size = ctx.getResult(SIZE_RESULT_VALUE, Long.class); - - log.info("Result: {} of size {}", type, size); - } - - @Test - void dataUrlDecode() { - final var ctx = dataUrlDecoderContentProcessor.then(base64DecoderContentProcessor).then(imageResizeContentProcessor) - .then(sizeContentProcessor).process(new ContentProcessorContext(new ByteArrayInputStream(DATA_URL), - Map.of(IMAGE_RESIZE_PARAM_MAX_WIDTH, 110, IMAGE_RESIZE_PARAM_MAX_HEIGHT, 110, IMAGE_RESIZE_PARAM_FORMAT, "png"))); - - write(ctx, "data-url-decode.png"); - - String type = ctx.getResult(DATA_URL_DECODE_RESULT_CONTENT_TYPE, String.class); - Long size = ctx.getResult(SIZE_RESULT_VALUE, Long.class); - - log.info("Result: {} of size {}", type, size); - } - - @Test - void dataUrlEncodePng() { - final var ctx = imageResizeContentProcessor.then(base64EncoderContentProcessor).then(dataUrlEncoderContentProcessor) - .process(new ContentProcessorContext(ContentProcessorTest.class.getClassLoader().getResourceAsStream("test.png"), - Map.of(IMAGE_RESIZE_PARAM_MAX_WIDTH, 110, IMAGE_RESIZE_PARAM_MAX_HEIGHT, 110, IMAGE_RESIZE_PARAM_FORMAT, "png", - DATA_URL_ENCODE_PARAM_CONTENT_TYPE, "image/png", DATA_URL_ENCODE_PARAM_ENCODING, "base64"))); - - write(ctx, "data-url-encode-png.txt"); - - String type = ctx.getResult(DATA_URL_DECODE_RESULT_CONTENT_TYPE, String.class); - Long size = ctx.getResult(SIZE_RESULT_VALUE, Long.class); - - log.info("Result: {} of size {}", type, size); - } - - @Test - void dataUrlEncodeJpeg() { - final var ctx = imageResizeContentProcessor.then(base64EncoderContentProcessor).then(dataUrlEncoderContentProcessor) - .process(new ContentProcessorContext(ContentProcessorTest.class.getClassLoader().getResourceAsStream("test-large.jpg"), - Map.of(IMAGE_RESIZE_PARAM_MAX_WIDTH, 300, IMAGE_RESIZE_PARAM_MAX_HEIGHT, 300, IMAGE_RESIZE_PARAM_FORMAT, "jpg", - DATA_URL_ENCODE_PARAM_CONTENT_TYPE, "image/png", DATA_URL_ENCODE_PARAM_ENCODING, "base64"))); - - write(ctx, "data-url-encode-jpg.txt"); - - String type = ctx.getResult(DATA_URL_DECODE_RESULT_CONTENT_TYPE, String.class); - Long size = ctx.getResult(SIZE_RESULT_VALUE, Long.class); - - log.info("Result: {} of size {}", type, size); - } - - @Test - void base64() { - final var ctx = base64DecoderContentProcessor.then(sizeContentProcessor).process(new ByteArrayInputStream(DATA_BASE64)); - - write(ctx, "base64.png"); - - String type = ctx.getResult(DATA_URL_DECODE_RESULT_CONTENT_TYPE, String.class); - Long size = ctx.getResult(SIZE_RESULT_VALUE, Long.class); - - log.info("Result: {} of size {}", type, size); - } - - private void write(ContentProcessorContext ctx, String fileName) { - try (var is = ctx.getInputStream(); var out = Files.newOutputStream(java.nio.file.Path.of("build/" + fileName))) { - is.transferTo(out); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -}