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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new fed5308b06e5 CAMEL-25656: camel-netty-http - available() of the 
request body stream cache returns the bytes left to read (#27859)
fed5308b06e5 is described below

commit fed5308b06e5294ecc4fa8a33e69364ada220a30
Author: allthingssecurity <[email protected]>
AuthorDate: Thu Oct 15 11:16:22 2026 +0530

    CAMEL-25656: camel-netty-http - available() of the request body stream 
cache returns the bytes left to read (#27859)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../netty/http/NettyChannelBufferStreamCache.java  |  6 ++++++
 .../http/NettyChannelBufferStreamCacheTest.java    | 24 ++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCache.java
 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCache.java
index 9f7305ff5939..91eb23da49f2 100644
--- 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCache.java
+++ 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCache.java
@@ -82,6 +82,12 @@ public final class NettyChannelBufferStreamCache extends 
InputStream implements
         return len;
     }
 
+    @Override
+    public int available() {
+        // the whole body is in memory, so what is left of it can be read 
without blocking
+        return buffer.readableBytes();
+    }
+
     @Override
     public void reset() {
         lock.lock();
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCacheTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCacheTest.java
index b25bbcb719fe..531403461236 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCacheTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCacheTest.java
@@ -146,6 +146,30 @@ class NettyChannelBufferStreamCacheTest {
         }
     }
 
+    @Test
+    void availableIsTheNumberOfBytesLeft() throws IOException {
+        // the capacity (16) is larger than the content (5 bytes)
+        ByteBuf buffer = Unpooled.buffer(16);
+        buffer.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
+        NettyChannelBufferStreamCache cache = new 
NettyChannelBufferStreamCache(buffer);
+        try {
+            assertEquals(5, cache.available());
+            cache.read();
+            assertEquals(4, cache.available());
+            cache.read(new byte[3]);
+            assertEquals(1, cache.available());
+            cache.read();
+            assertEquals(0, cache.available());
+            assertEquals(-1, cache.read());
+            assertEquals(0, cache.available());
+
+            cache.reset();
+            assertEquals(5, cache.available());
+        } finally {
+            release(cache);
+        }
+    }
+
     private static void release(NettyChannelBufferStreamCache cache) {
         // once for the buffer that the test created and once for the retain 
of the cache
         cache.release();

Reply via email to