diff --git a/core-util-jvm/src/main/java/org/signal/core/util/stream/LimitedInputStream.kt b/core-util-jvm/src/main/java/org/signal/core/util/stream/LimitedInputStream.kt index 67d6f91826..6a58fdf22f 100644 --- a/core-util-jvm/src/main/java/org/signal/core/util/stream/LimitedInputStream.kt +++ b/core-util-jvm/src/main/java/org/signal/core/util/stream/LimitedInputStream.kt @@ -5,6 +5,7 @@ package org.signal.core.util.stream +import org.signal.core.util.logging.Log import java.io.FilterInputStream import java.io.InputStream import java.lang.UnsupportedOperationException @@ -24,6 +25,8 @@ class LimitedInputStream(private val wrapped: InputStream, private val maxBytes: private const val UNLIMITED = -1L + private val TAG = Log.tag(LimitedInputStream::class) + /** * Returns a [LimitedInputStream] that doesn't limit the stream at all -- it'll allow reading the full thing. */ @@ -143,7 +146,7 @@ class LimitedInputStream(private val wrapped: InputStream, private val maxBytes: } if (totalBytesRead < maxBytes) { - throw IllegalStateException("Stream has not been fully read") + Log.w(TAG, "Reading leftover stream when the stream has not been fully read! maxBytes is $maxBytes, but we've only read $totalBytesRead") } return wrapped diff --git a/core-util-jvm/src/test/java/org/signal/core/util/stream/LimitedInputStreamTest.kt b/core-util-jvm/src/test/java/org/signal/core/util/stream/LimitedInputStreamTest.kt index 35d338c5f5..dd2ac665da 100644 --- a/core-util-jvm/src/test/java/org/signal/core/util/stream/LimitedInputStreamTest.kt +++ b/core-util-jvm/src/test/java/org/signal/core/util/stream/LimitedInputStreamTest.kt @@ -96,12 +96,6 @@ class LimitedInputStreamTest { assertEquals(25, truncatedBytes.size) } - @Test(expected = IllegalStateException::class) - fun `if I have not finished reading the stream, leftoverStream throws IllegalStateException`() { - val inputStream = LimitedInputStream(ByteArray(100).inputStream(), maxBytes = 75) - inputStream.leftoverStream() - } - @Test fun `when call leftoverStream on a stream with no limit, it returns an empty array`() { val inputStream = LimitedInputStream.withoutLimits(ByteArray(100).inputStream())