ProxyOutputStream: Extend OutputStream

This commit is contained in:
Paul Schaub 2023-11-15 12:42:56 +01:00
parent edef899074
commit 41acdfe03a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -15,7 +15,7 @@ import java.io.OutputStream
* class is useful if we need to provide an [OutputStream] at one point in time when the final * class is useful if we need to provide an [OutputStream] at one point in time when the final
* target output stream is not yet known. * target output stream is not yet known.
*/ */
class ProxyOutputStream { class ProxyOutputStream : OutputStream() {
private val buffer = ByteArrayOutputStream() private val buffer = ByteArrayOutputStream()
private var swapped: OutputStream? = null private var swapped: OutputStream? = null
@ -27,7 +27,7 @@ class ProxyOutputStream {
@Synchronized @Synchronized
@Throws(IOException::class) @Throws(IOException::class)
fun write(b: ByteArray) { override fun write(b: ByteArray) {
if (swapped == null) { if (swapped == null) {
buffer.write(b) buffer.write(b)
} else { } else {
@ -37,7 +37,7 @@ class ProxyOutputStream {
@Synchronized @Synchronized
@Throws(IOException::class) @Throws(IOException::class)
fun write(b: ByteArray, off: Int, len: Int) { override fun write(b: ByteArray, off: Int, len: Int) {
if (swapped == null) { if (swapped == null) {
buffer.write(b, off, len) buffer.write(b, off, len)
} else { } else {
@ -47,7 +47,7 @@ class ProxyOutputStream {
@Synchronized @Synchronized
@Throws(IOException::class) @Throws(IOException::class)
fun flush() { override fun flush() {
buffer.flush() buffer.flush()
if (swapped != null) { if (swapped != null) {
swapped!!.flush() swapped!!.flush()
@ -56,7 +56,7 @@ class ProxyOutputStream {
@Synchronized @Synchronized
@Throws(IOException::class) @Throws(IOException::class)
fun close() { override fun close() {
buffer.close() buffer.close()
if (swapped != null) { if (swapped != null) {
swapped!!.close() swapped!!.close()
@ -65,7 +65,7 @@ class ProxyOutputStream {
@Synchronized @Synchronized
@Throws(IOException::class) @Throws(IOException::class)
fun write(i: Int) { override fun write(i: Int) {
if (swapped == null) { if (swapped == null) {
buffer.write(i) buffer.write(i)
} else { } else {