From 8d90a70b6a9870bc4f9e3d64624dfe732a82d897 Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 13 Feb 2020 18:58:55 +0000 Subject: [PATCH] Fix SkipOutputStream Calling super.write(byte[], int, int) in FilterOutputStream didn't work, as it called super.write(byte). This is inefficient and also caused us to fiddle with skipBytes twice, causing us to skip the incorrect number of bytes. --- .../dev/openrs2/common/io/SkipOutputStream.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/dev/openrs2/common/io/SkipOutputStream.kt b/common/src/main/java/dev/openrs2/common/io/SkipOutputStream.kt index 12b68c65..e9bbe3ff 100644 --- a/common/src/main/java/dev/openrs2/common/io/SkipOutputStream.kt +++ b/common/src/main/java/dev/openrs2/common/io/SkipOutputStream.kt @@ -1,12 +1,11 @@ package dev.openrs2.common.io -import java.io.FilterOutputStream import java.io.OutputStream -class SkipOutputStream(out: OutputStream, private var skipBytes: Long) : FilterOutputStream(out) { +class SkipOutputStream(private val out: OutputStream, private var skipBytes: Long) : OutputStream() { override fun write(b: Int) { if (skipBytes == 0L) { - super.write(b) + out.write(b) } else { skipBytes-- } @@ -14,10 +13,18 @@ class SkipOutputStream(out: OutputStream, private var skipBytes: Long) : FilterO override fun write(b: ByteArray, off: Int, len: Int) { if (len >= skipBytes) { - super.write(b, off + skipBytes.toInt(), len - skipBytes.toInt()) + out.write(b, off + skipBytes.toInt(), len - skipBytes.toInt()) skipBytes = 0 } else { skipBytes -= len } } + + override fun flush() { + out.flush() + } + + override fun close() { + out.close() + } }