diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java index 63cee0af9..ef33c7295 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java @@ -55,7 +55,7 @@ protected int capacityIncrement() { @Override protected void data(final ByteBuffer src, final boolean endOfStream) throws ContentTooLongException { - if (src.capacity() > limit) { + if (buffer.length() + src.limit() > limit) { throw new ContentTooLongException( "entity content is too long [" + src.capacity() + "] for the configured buffer limit [" + limit + "]" );