Make LimitedInputStream less strict.
This commit is contained in:
parent
1f638db959
commit
fcb2e3cc74
2 changed files with 4 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Reference in a new issue