You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2022/09/19 04:41:50 UTC

[sling-org-apache-sling-distribution-core] branch master updated: SLING-11586: FileBackedMemoryOutputStream tests fails on Windows due to unclosed streams

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 9adf47cd SLING-11586: FileBackedMemoryOutputStream tests fails on Windows due to unclosed streams
     new a0daabdc Merge pull request #64 from reschke/SLING-11586
9adf47cd is described below

commit 9adf47cdd8c9521cc1a27ed6d7a314320bd0a6e8
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Sat Sep 17 08:15:27 2022 +0100

    SLING-11586: FileBackedMemoryOutputStream tests fails on Windows due to unclosed streams
---
 .../distribution/util/impl/ByteBufferBackedInputStream.java   |  8 ++++++++
 .../util/impl/FileBackedMemoryOutputStreamTest.java           | 11 ++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/distribution/util/impl/ByteBufferBackedInputStream.java b/src/main/java/org/apache/sling/distribution/util/impl/ByteBufferBackedInputStream.java
index 35e8bd03..4cc7f469 100644
--- a/src/main/java/org/apache/sling/distribution/util/impl/ByteBufferBackedInputStream.java
+++ b/src/main/java/org/apache/sling/distribution/util/impl/ByteBufferBackedInputStream.java
@@ -43,6 +43,7 @@ final class ByteBufferBackedInputStream extends InputStream {
         }
     }
 
+    @Override
     public int read() throws IOException {
         if (!memory.hasRemaining()) {
             if (fileInputStream != null) {
@@ -54,6 +55,7 @@ final class ByteBufferBackedInputStream extends InputStream {
         return memory.get() & 0xFF;
     }
 
+    @Override
     public int read(@NotNull byte[] bytes, int off, int len) throws IOException {
         if (!memory.hasRemaining()) {
             if (fileInputStream != null) {
@@ -68,4 +70,10 @@ final class ByteBufferBackedInputStream extends InputStream {
         return len;
     }
 
+    @Override
+    public void close() throws IOException {
+        if (fileInputStream != null) {
+            fileInputStream.close();
+        }
+    }
 }
diff --git a/src/test/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStreamTest.java b/src/test/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStreamTest.java
index b0f8bac6..c0db502b 100644
--- a/src/test/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStreamTest.java
+++ b/src/test/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStreamTest.java
@@ -158,11 +158,12 @@ public class FileBackedMemoryOutputStreamTest {
     }
 
     private void verifyWrittenData(FileBackedMemoryOutputStream writtenData, byte... expecteds) throws IOException {
-        InputStream input = writtenData.openWrittenDataInputStream();
-        ByteArrayOutputStream output = new ByteArrayOutputStream();
-        copy(input, output);
-        byte[] actuals = output.toByteArray();
-        assertArrayEquals(expecteds, actuals);
+        try (InputStream input = writtenData.openWrittenDataInputStream()) {
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            copy(input, output);
+            byte[] actuals = output.toByteArray();
+            assertArrayEquals(expecteds, actuals);
+        }
     }
 
 }