• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pgpainless / sop-java / #52

15 May 2025 12:16AM UTC coverage: 60.782% (-2.4%) from 63.194%
#52

push

other

vanitasvitae
Try to fix coveralls repo token

1773 of 2917 relevant lines covered (60.78%)

0.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.0
/sop-java/src/main/kotlin/sop/util/ProxyOutputStream.kt
1
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
2
//
3
// SPDX-License-Identifier: Apache-2.0
4

5
package sop.util
6

7
import java.io.ByteArrayOutputStream
8
import java.io.IOException
9
import java.io.OutputStream
10

11
/**
12
 * [OutputStream] that buffers data being written into it, until its underlying output stream is
13
 * being replaced. At that point, first all the buffered data is being written to the underlying
14
 * stream, followed by any successive data that may get written to the [ProxyOutputStream]. This
15
 * class is useful if we need to provide an [OutputStream] at one point in time when the final
16
 * target output stream is not yet known.
17
 */
18
@Deprecated("Marked for removal.")
19
// TODO: Remove in 11.X
20
class ProxyOutputStream : OutputStream() {
1✔
21
    private val buffer = ByteArrayOutputStream()
1✔
22
    private var swapped: OutputStream? = null
23

24
    @Synchronized
25
    fun replaceOutputStream(underlying: OutputStream) {
26
        this.swapped = underlying
1✔
27
        swapped!!.write(buffer.toByteArray())
1✔
28
    }
1✔
29

30
    @Synchronized
31
    @Throws(IOException::class)
32
    override fun write(b: ByteArray) {
33
        if (swapped == null) {
1✔
34
            buffer.write(b)
1✔
35
        } else {
36
            swapped!!.write(b)
1✔
37
        }
38
    }
1✔
39

40
    @Synchronized
41
    @Throws(IOException::class)
42
    override fun write(b: ByteArray, off: Int, len: Int) {
43
        if (swapped == null) {
×
44
            buffer.write(b, off, len)
×
45
        } else {
46
            swapped!!.write(b, off, len)
×
47
        }
48
    }
×
49

50
    @Synchronized
51
    @Throws(IOException::class)
52
    override fun flush() {
53
        buffer.flush()
×
54
        if (swapped != null) {
×
55
            swapped!!.flush()
×
56
        }
57
    }
×
58

59
    @Synchronized
60
    @Throws(IOException::class)
61
    override fun close() {
62
        buffer.close()
1✔
63
        if (swapped != null) {
1✔
64
            swapped!!.close()
1✔
65
        }
66
    }
1✔
67

68
    @Synchronized
69
    @Throws(IOException::class)
70
    override fun write(i: Int) {
71
        if (swapped == null) {
×
72
            buffer.write(i)
×
73
        } else {
74
            swapped!!.write(i)
×
75
        }
76
    }
×
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc