mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 00:29:11 +01:00
Improve memory usage of new APNG renderer by making it streaming.
This commit is contained in:
committed by
Cody Henthorne
parent
48374e6950
commit
25b01a30be
@@ -139,6 +139,27 @@ fun InputStream.copyTo(outputStream: OutputStream, closeInputStream: Boolean = t
|
||||
return StreamUtil.copy(this, outputStream, closeInputStream, closeOutputStream)
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips exactly [n] bytes from this stream. Unlike [InputStream.skip], this method
|
||||
* guarantees all bytes are skipped by looping and falling back to [read] if needed.
|
||||
*
|
||||
* @throws IOException if the stream ends before [n] bytes have been skipped.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun InputStream.skipNBytesOrThrow(n: Long) {
|
||||
var remaining = n
|
||||
while (remaining > 0) {
|
||||
val skipped = skip(remaining)
|
||||
if (skipped > 0) {
|
||||
remaining -= skipped
|
||||
} else if (read() == -1) {
|
||||
throw IOException("Stream ended before $n bytes could be skipped (${n - remaining} skipped)")
|
||||
} else {
|
||||
remaining--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if every byte in this stream matches the predicate, otherwise false.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user