Github user dineshjoshi commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/239#discussion_r202489810
--- Diff:
src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java ---
@@ -249,4 +250,42 @@ public ByteBufAllocator getAllocator()
{
return channelConfig.getAllocator();
}
+
+ /**
+ * Consumes bytes in the stream until the given length
+ *
+ * @param writer
+ * @param len
+ * @return
+ * @throws IOException
+ */
+ public long consumeUntil(BufferedDataOutputStreamPlus writer, long
len) throws IOException
+ {
+ long copied = 0; // number of bytes copied
+ while (copied < len)
+ {
+ if (buffer.remaining() == 0)
+ {
+ try
+ {
+ reBuffer();
+ }
+ catch (EOFException e)
+ {
+ throw new EOFException("EOF after " + copied + " bytes
out of " + len);
+ }
+ if (buffer.remaining() == 0)
+ return copied == 0 ? -1 : copied;
--- End diff --
Re-reading the code, the check on [line
227](https://github.com/dineshjoshi/cassandra/blob/f9573ccef63535b787e91e46fa886f3e3ff2eee8/src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java#L277)
is just being over cautious in case the `reBuffer` implementation changes and
can return a empty buffer.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]