diff --git a/hapi-hl7overhttp/src/main/java/ca/uhn/hl7v2/hoh/encoder/AbstractHl7OverHttpDecoder.java b/hapi-hl7overhttp/src/main/java/ca/uhn/hl7v2/hoh/encoder/AbstractHl7OverHttpDecoder.java index 0878b8051..5c188f3f9 100644 --- a/hapi-hl7overhttp/src/main/java/ca/uhn/hl7v2/hoh/encoder/AbstractHl7OverHttpDecoder.java +++ b/hapi-hl7overhttp/src/main/java/ca/uhn/hl7v2/hoh/encoder/AbstractHl7OverHttpDecoder.java @@ -273,7 +273,7 @@ private byte[] readBytesChunked(InputStream theInputStream) throws DecodeExcepti int totalRead = 0; myLastStartedReading = System.currentTimeMillis(); do { - int nextRead = Math.min(nextSizeInt, byteBuffer.length); + int nextRead = Math.min(nextSizeInt - totalRead, byteBuffer.length); int bytesRead = theInputStream.read(byteBuffer, 0, nextRead); if (bytesRead == -1) { ourLog.debug("Exception in readBytesChunked(InputStream): Reached EOF. Buffer has {} bytes", bos.size());