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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 349f7b774 SeekableInMemoryByteChannel.SeekableInMemoryByteChannel() 
internal buffer now defaults to IOUtils.DEFAULT_BUFFER_SIZE
349f7b774 is described below

commit 349f7b774618874145203aff017302eb77dbb5f5
Author: Gary D. Gregory <[email protected]>
AuthorDate: Sun Sep 21 10:58:00 2025 -0400

    SeekableInMemoryByteChannel.SeekableInMemoryByteChannel() internal
    buffer now defaults to IOUtils.DEFAULT_BUFFER_SIZE
---
 src/changes/changes.xml                            |  1 +
 .../utils/SeekableInMemoryByteChannel.java         |  5 ++--
 .../utils/SeekableInMemoryByteChannelTest.java     | 29 +++++++++++++---------
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 12c44e71a..07c778527 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -99,6 +99,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Normalize 
exception message sentences to start with a capital letter.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate 
ByteUtils.EMPTY_BYTE_ARRAY in favor or ArrayUtils.EMPTY_BYTE_ARRAY.</action>
       <action type="fix" dev="ggregory" due-to="Martin Wiesner, Gary 
Gregory">Fix grammar issues and typos #687.</action>
+      <action type="fix" dev="ggregory" due-to="Gary 
Gregory">SeekableInMemoryByteChannel.SeekableInMemoryByteChannel() internal 
buffer now defaults to IOUtils.DEFAULT_BUFFER_SIZE.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
MemoryLimitException.MemoryLimitException(long, long).</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
CompressException.CompressException(String, Object...).</action>
diff --git 
a/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
 
b/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
index 7055f6bbf..fb41df94c 100644
--- 
a/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
+++ 
b/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
@@ -26,7 +26,7 @@
 import java.util.Arrays;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.io.IOUtils;
 
 /**
  * A {@link SeekableByteChannel} implementation that wraps a byte array.
@@ -54,7 +54,8 @@ public class SeekableInMemoryByteChannel implements 
SeekableByteChannel {
      * Constructs a new instance using a default empty buffer.
      */
     public SeekableInMemoryByteChannel() {
-        this(ArrayUtils.EMPTY_BYTE_ARRAY);
+        //this(ArrayUtils.EMPTY_BYTE_ARRAY);
+        this(IOUtils.DEFAULT_BUFFER_SIZE);
     }
 
     /**
diff --git 
a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
 
b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
index f3016fcaa..7e1c6ebce 100644
--- 
a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
+++ 
b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.commons.compress.utils;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -28,14 +27,17 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.SeekableByteChannel;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 class SeekableInMemoryByteChannelTest {
 
-    private final byte[] testData = "Some data".getBytes(UTF_8);
+    private final byte[] testData = "Some 
data".getBytes(StandardCharsets.UTF_8);
 
     /*
      * <q>If the stream is already closed then invoking this method has no 
effect.</q>
@@ -54,13 +56,16 @@ void testCloseIsIdempotent() throws Exception {
      * <q>Setting the position to a value that is greater than the current 
size is legal but does not change the size of the entity. A later attempt to 
read
      * bytes at such a position will immediately return an end-of-file 
indication</q>
      */
-    @Test
-    void testReadingFromAPositionAfterEndReturnsEOF() throws Exception {
-        try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) {
-            c.position(2);
-            assertEquals(2, c.position());
-            final ByteBuffer readBuffer = ByteBuffer.allocate(5);
-            assertEquals(-1, c.read(readBuffer));
+    @ParameterizedTest
+    @ValueSource(ints = { 0, 1, 2, 3, 4, 5, 6 })
+    void testReadingFromAPositionAfterEndReturnsEOF(final int size) throws 
Exception {
+        try (SeekableByteChannel c = new SeekableInMemoryByteChannel(size)) {
+            final int position = 2;
+            c.position(position);
+            assertEquals(position, c.position());
+            final int readSize = 5;
+            final ByteBuffer readBuffer = ByteBuffer.allocate(readSize);
+            assertEquals(position >= size ? -1 : size - position, 
c.read(readBuffer));
         }
     }
 
@@ -102,7 +107,7 @@ void testShouldReadDataFromSetPosition() throws IOException 
{
             final int readCount = c.read(readBuffer);
             // then
             assertEquals(4L, readCount);
-            assertEquals("data", new String(readBuffer.array(), UTF_8));
+            assertEquals("data", new String(readBuffer.array(), 
StandardCharsets.UTF_8));
             assertEquals(testData.length, c.position());
         }
     }
@@ -194,7 +199,7 @@ void testShouldTruncateContentsProperly() {
             c.truncate(4);
             // then
             final byte[] bytes = Arrays.copyOf(c.array(), (int) c.size());
-            assertEquals("Some", new String(bytes, UTF_8));
+            assertEquals("Some", new String(bytes, StandardCharsets.UTF_8));
         }
     }
 
@@ -211,8 +216,8 @@ void testShouldWriteDataProperly() throws IOException {
             final int writeCount = c.write(inData);
             // then
             assertEquals(testData.length, writeCount);
-            assertArrayEquals(testData, Arrays.copyOf(c.array(), (int) 
c.size()));
             assertEquals(testData.length, c.position());
+            assertArrayEquals(testData, Arrays.copyOf(c.array(), (int) 
c.position()));
         }
     }
 

Reply via email to