From 940dc7233730ba3cfabc04d1e9e0e8209bc79b6d Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Wed, 22 May 2024 14:31:30 -0600 Subject: [PATCH] Add test for writeToStream with offset and size --- .../thredds/inventory/zarr/TestMFileZip.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java b/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java index bbfa09d8c8..52202feb02 100644 --- a/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java +++ b/cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java @@ -55,6 +55,25 @@ public void shouldWriteZipToStream() throws IOException { assertThat(outputStream.size()).isEqualTo(mFile.getLength()); } } + + @Test + public void shouldWritePartialZipToStream() throws IOException { + try (ZipFile zipFile = createTemporaryZipFile("TestWritePartialZip", entrySize, numberOfEntries)) { + final MFileZip mFile = new MFileZip(zipFile.getName()); + final int length = (int) mFile.getLength(); + + final int offset = 1; + final int maxBytes = 100; + + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + final int startPosition = Math.min(offset, length); + final int endPosition = Math.min(offset + maxBytes, length); + + mFile.writeToStream(outputStream, offset, maxBytes); + assertThat(outputStream.size()).isEqualTo(Math.max(0, endPosition - startPosition)); + } + } } public static class TestMFileZipNonParameterized {