davsclaus commented on code in PR #27757:
URL: https://github.com/apache/camel/pull/27757#discussion_r4255125922


##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyChannelBufferStreamCache.java:
##########
@@ -46,14 +46,20 @@ public NettyChannelBufferStreamCache(ByteBuf buffer) {
         this.buffer.markReaderIndex();
     }
 
+    /**
+     * Marking is not supported: {@link #mark(int)} does nothing, and {@link 
#reset()} always goes back to the start of
+     * the body, which is what {@link StreamCache#reset()} is for. A reader 
that needs mark support has to wrap this
+     * stream (for example in a {@link java.io.BufferedInputStream}), and so 
cannot change where a reset goes back to.
+     */
     @Override
     public boolean markSupported() {
-        return true;
+        return false;
     }
 
     @Override
     public int read() {
-        return buffer.readByte();
+        // an unsigned byte, and -1 at the end, as InputStream requires
+        return buffer.isReadable() ? buffer.readByte() & 0xFF : -1;
     }

Review Comment:
   Optional, since you are completing the `InputStream` contract here: 
`available()` is not overridden, so it returns 0 even when the whole body is in 
memory. That is legal, but some readers use it, e.g. 
`java.util.zip.GZIPInputStream.readTrailer()` checks `in.available() > 0` to 
decide whether a concatenated gzip member follows. Returning the readable bytes 
would be cheap:
   
   ```suggestion
       }
   
       @Override
       public int available() {
           return buffer.readableBytes();
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to