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

synadia-io / nats.java.v3 / 36791038761

30 Sep 2026 11:25PM UTC coverage: 90.839% (-0.03%) from 90.87%
36791038761

push

github

scottf
Windows build tests only the affected modules

- build-windows.yml gets the same changes job as the module builds; the Windows job is skipped when no module is affected and otherwise runs :<module>:test for each affected module in one job, so nats-server is built once
- test report upload paths point at each module's build directory
- affected-modules.sh treats a build-windows.yml change as affecting every module

4187 of 4830 branches covered (86.69%)

Branch coverage included in aggregate %.

10647 of 11500 relevant lines covered (92.58%)

4.12 hits per line

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

85.07
/core/src/main/java/io/synadia/client/utils/WebsocketInputStream.java
1
package io.synadia.client.utils;
2

3
import io.synadia.client.utils.WebsocketFrameHeader.OpCode;
4

5
import java.io.IOException;
6
import java.io.InputStream;
7

8
/**
9
 * An InputStream that strips the websocket frame headers off the wrapped stream,
10
 * exposing only the payload bytes. A CLOSE frame reads as end of stream.
11
 */
12
public class WebsocketInputStream extends InputStream {
13
    private byte[] buffer = new byte[WebsocketFrameHeader.MAX_FRAME_HEADER_SIZE];
4 ✔
14
    private WebsocketFrameHeader header = new WebsocketFrameHeader();
5 ✔
15
    private InputStream in;
16
    private byte[] oneByte = new byte[1];
4 ✔
17

18
    /**
19
     * Construct the stream over a raw socket input stream positioned at a frame header.
20
     * @param in the underlying stream
21
     */
22
    public WebsocketInputStream(InputStream in) {
2 ✔
23
        this.in = in;
3 ✔
24
    }
1 ✔
25

26
    @Override
27
    public int available() throws IOException {
28
        return in.available();
4 ✔
29
    }
30

31
    @Override
32
    public void close() throws IOException {
33
        in.close();
3 ✔
34
    }
1 ✔
35

36
    @Override
37
    public void mark(int readLimit) {
38

39
    }
1 ✔
40

41
    @Override
42
    public boolean markSupported() {
43
        return false;
2 ✔
44
    }
45

46
    @Override
47
    public int read(byte[] buffer) throws IOException {
48
        return read(buffer, 0, buffer.length);
7 ✔
49
    }
50

51
    @Override
52
    public int read(byte[] buffer, int offset, int length) throws IOException {
53
        // Just in case we get headers with empty payloads:
54
        while (0 == header.getPayloadLength()) {
6 ✔
55
            if (!readHeader()) {
3 ✔
56
                return -1;
2 ✔
57
            }
58
        }
59
        if (header.getOpCode() == OpCode.CLOSE) {
5 !
60
            // Ignore the websocket close message body:
61
            in.skip(header.getPayloadLength());
×
62
            return -1;
×
63
        }
64
        final long headerPayloadLength = header.getPayloadLength();
4 ✔
65
        final int payloadLength = Math.min(length, headerPayloadLength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)headerPayloadLength);
9 !
66
        length = in.read(buffer, offset, payloadLength);
7 ✔
67
        if (-1 == length) {
3 !
68
            return length;
×
69
        }
70
        return header.filterPayload(buffer, offset, length);
7 ✔
71
    }
72

73
    @Override
74
    public int read() throws IOException {
75
        int result = read(oneByte, 0, 1);
7 ✔
76
        if (-1 == result) {
3 !
77
            return result;
×
78
        }
79
        return oneByte[0];
5 ✔
80
    }
81

82
    private boolean readHeader() throws IOException {
83
        int len = 0;
2 ✔
84
        while (len < 2) {
3 ✔
85
            int result = in.read(buffer, len, 2 - len);
10 ✔
86
            if (result < 0) {
2 ✔
87
                return false;
2 ✔
88
            }
89
            len += result;
4 ✔
90
        }
1 ✔
91
        int headerSize = WebsocketFrameHeader.size(buffer, 0);
5 ✔
92
        if (headerSize > 2) {
3 ✔
93
            while (len < headerSize) {
3 ✔
94
                int result = in.read(buffer, len, headerSize - len);
10 ✔
95
                if (result < 0) {
2 !
96
                    return false;
×
97
                }
98
                len += result;
4 ✔
99
            }
1 ✔
100
        }
101
        header.write(buffer, 0, headerSize);
8 ✔
102
        return true;
2 ✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc