Skip to content

CAMEL-22721 Use CachedOutputStream to enable streaming of large zip f…#21249

Open
lantzen wants to merge 1 commit intoapache:mainfrom
lantzen:CAMEL-22721
Open

CAMEL-22721 Use CachedOutputStream to enable streaming of large zip f…#21249
lantzen wants to merge 1 commit intoapache:mainfrom
lantzen:CAMEL-22721

Conversation

@lantzen
Copy link
Contributor

@lantzen lantzen commented Feb 4, 2026

…iles

Description

Use CachedOutputStream to enable streaming of large zip files and added tests that verify that the ZipSplitter doesn't read the whole files in the zip file into memory

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

private int testSplitterLargeFile(File testFile) throws IOException, FileNotFoundException, InterruptedException {
String expectedBody = null;

System.out.println("Generating 50MB test file...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove or change to log.info


if ("testSplitterLargeFileWithSpoolEnabled()".equals(contextManagerExtension.getCurrentTestName())) {
StreamCachingStrategy streamCachingStrategy = context.getStreamCachingStrategy();
streamCachingStrategy.setSpoolEnabled(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default spool threshold is 128kb


public class ZipSplitterRouteTest extends CamelTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(ZipIterator.class);

private static final File testDirectory = new File("test/in");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use JUnit TempDir?

IOHelper.copy(zipInputStream, baos);
byte[] data = baos.toByteArray();
answer.setBody(new ByteArrayInputStream(data));
CachedOutputStream cos = new CachedOutputStream(exchange);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who is supposed to close this stream?

@davsclaus

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the zip iterator should close it when its done, I would assume when itself is closed - the COS may spool to disk and therefore need to be closed so it can delete the temp file

}

private void captureMemory(AtomicInteger storage, String logPrefix) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.gc() is not reliable, I'd remove this captureMemory()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants