This is an automated email from the ASF dual-hosted git repository.
tilman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new 23eee9221 TIKA-4525: close inputstream
23eee9221 is described below
commit 23eee9221becb2bf137a9ba796e26f0b6a9e346b
Author: Tilman Hausherr <[email protected]>
AuthorDate: Fri Oct 24 09:32:52 2025 +0200
TIKA-4525: close inputstream
---
.../org/apache/tika/pipes/s3/tests/S3PipeIntegrationTest.java | 11 ++++++-----
.../main/java/org/apache/tika/pipes/fetcher/s3/S3Fetcher.java | 5 ++++-
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git
a/tika-integration-tests/tika-pipes-s3-integration-tests/src/test/java/org/apache/tika/pipes/s3/tests/S3PipeIntegrationTest.java
b/tika-integration-tests/tika-pipes-s3-integration-tests/src/test/java/org/apache/tika/pipes/s3/tests/S3PipeIntegrationTest.java
index 5e7ad0d98..cb2a85fb0 100644
---
a/tika-integration-tests/tika-pipes-s3-integration-tests/src/test/java/org/apache/tika/pipes/s3/tests/S3PipeIntegrationTest.java
+++
b/tika-integration-tests/tika-pipes-s3-integration-tests/src/test/java/org/apache/tika/pipes/s3/tests/S3PipeIntegrationTest.java
@@ -152,11 +152,12 @@ class S3PipeIntegrationTest {
for (String testFile : testFiles) {
GetObjectRequest objectRequest =
GetObjectRequest.builder().bucket(EMIT_BUCKET).key(testFile + ".json").build();
- ResponseInputStream<GetObjectResponse> object =
s3Client.getObject(objectRequest);
- Assertions.assertNotNull(object);
- String data = IOUtils.toString(object, StandardCharsets.UTF_8);
- Assertions.assertTrue(data.contains("body-of-" + testFile),
- "Should be able to read the parsed body of the HTML file
as the body of the document");
+ try (ResponseInputStream<GetObjectResponse> is =
s3Client.getObject(objectRequest)) {
+ Assertions.assertNotNull(is);
+ String data = IOUtils.toString(is, StandardCharsets.UTF_8);
+ Assertions.assertTrue(data.contains("body-of-" + testFile),
+ "Should be able to read the parsed body of the HTML
file as the body of the document");
+ }
}
}
diff --git
a/tika-pipes/tika-fetchers/tika-fetcher-s3/src/main/java/org/apache/tika/pipes/fetcher/s3/S3Fetcher.java
b/tika-pipes/tika-fetchers/tika-fetcher-s3/src/main/java/org/apache/tika/pipes/fetcher/s3/S3Fetcher.java
index 178472ddc..c6dba4201 100644
---
a/tika-pipes/tika-fetchers/tika-fetcher-s3/src/main/java/org/apache/tika/pipes/fetcher/s3/S3Fetcher.java
+++
b/tika-pipes/tika-fetchers/tika-fetcher-s3/src/main/java/org/apache/tika/pipes/fetcher/s3/S3Fetcher.java
@@ -199,6 +199,7 @@ public class S3Fetcher extends AbstractFetcher implements
Initializable, RangeFe
private InputStream _fetch(String fetchKey, Metadata metadata,
Long startRange, Long endRange) throws
IOException {
TemporaryResources tmp = null;
+ ResponseInputStream<GetObjectResponse> s3Object = null;
try {
long start = System.currentTimeMillis();
GetObjectRequest.Builder builder =
GetObjectRequest.builder().bucket(bucket).key(fetchKey);
@@ -208,7 +209,6 @@ public class S3Fetcher extends AbstractFetcher implements
Initializable, RangeFe
builder.range(range);
}
GetObjectRequest objectRequest = builder.build();
- ResponseInputStream<GetObjectResponse> s3Object = null;
synchronized (clientLock) {
s3Object = s3Client.getObject(objectRequest);
}
@@ -242,6 +242,9 @@ public class S3Fetcher extends AbstractFetcher implements
Initializable, RangeFe
if (tmp != null) {
tmp.close();
}
+ if (s3Object != null) {
+ s3Object.close();
+ }
throw e;
}
}