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

leonchen83 / redis-replicator / #2552

01 Oct 2025 11:40AM UTC coverage: 72.206% (-0.03%) from 72.236%
#2552

push

leonchen83
Bump org.sonatype.central:central-publishing-maven-plugin

Bumps [org.sonatype.central:central-publishing-maven-plugin](https://github.com/sonatype/central-publishing-maven-plugin) from 0.8.0 to 0.9.0.
- [Commits](https://github.com/sonatype/central-publishing-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: org.sonatype.central:central-publishing-maven-plugin
  dependency-version: 0.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

7165 of 9923 relevant lines covered (72.21%)

0.72 hits per line

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

87.07
/src/main/java/com/moilioncircle/redis/replicator/io/RedisInputStream.java
1
/*
2
 * Copyright 2016-2018 Leon Chen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.moilioncircle.redis.replicator.io;
18

19
import com.moilioncircle.redis.replicator.util.ByteArray;
20
import com.moilioncircle.redis.replicator.util.Strings;
21

22
import java.io.EOFException;
23
import java.io.IOException;
24
import java.io.InputStream;
25
import java.nio.charset.Charset;
26
import java.util.Arrays;
27
import java.util.List;
28

29
/**
30
 * @author Leon Chen
31
 * @since 2.1.0
32
 */
33
public class RedisInputStream extends InputStream {
34
    protected int head = 0;
1✔
35
    protected int tail = 0;
1✔
36
    protected long total = 0;
1✔
37
    protected long markLen = 0;
1✔
38
    protected final byte[] buf;
39
    protected boolean mark = false;
1✔
40
    protected final InputStream in;
41
    protected List<RawByteListener> rawByteListeners;
42

43
    public RedisInputStream(ByteArray array) {
44
        this(new ByteArrayInputStream(array));
1✔
45
    }
1✔
46

47
    public RedisInputStream(final InputStream in) {
48
        this(in, 8192);
1✔
49
    }
1✔
50

51
    public RedisInputStream(final InputStream in, int len) {
1✔
52
        this.in = in;
1✔
53
        this.buf = new byte[len];
1✔
54
    }
1✔
55

56
    /**
57
     * @param rawByteListeners raw byte listeners
58
     * @since 2.2.0
59
     */
60
    public synchronized void setRawByteListeners(List<RawByteListener> rawByteListeners) {
61
        this.rawByteListeners = rawByteListeners;
1✔
62
    }
1✔
63

64
    protected void notify(byte... bytes) {
65
        if (rawByteListeners == null || rawByteListeners.isEmpty()) return;
1✔
66
        for (RawByteListener listener : rawByteListeners) {
1✔
67
            listener.handle(bytes);
1✔
68
        }
1✔
69
    }
1✔
70

71
    public int head() {
72
        return head;
×
73
    }
74

75
    public int tail() {
76
        return tail;
×
77
    }
78

79
    public int bufSize() {
80
        return buf.length;
×
81
    }
82

83
    public boolean isMarked() {
84
        return mark;
×
85
    }
86

87
    public void mark(long len) {
88
        mark();
×
89
        markLen = len;
×
90
    }
×
91

92
    public void mark() {
93
        if (!mark) {
1✔
94
            mark = true;
1✔
95
            return;
1✔
96
        }
97
        throw new AssertionError("already marked");
×
98
    }
99

100
    public long unmark() {
101
        if (mark) {
1✔
102
            long rs = markLen;
1✔
103
            markLen = 0;
1✔
104
            mark = false;
1✔
105
            return rs;
1✔
106
        }
107
        throw new AssertionError("must mark first");
×
108
    }
109

110
    public long total() {
111
        return total;
×
112
    }
113

114
    public ByteArray readBytes(long len) throws IOException {
115
        ByteArray bytes = new ByteArray(len);
1✔
116
        this.read(bytes, 0, len);
1✔
117
        if (mark) markLen += len;
1✔
118
        return bytes;
1✔
119
    }
120

121
    public int readInt(int len) throws IOException {
122
        return readInt(len, true);
1✔
123
    }
124

125
    public long readLong(int len) throws IOException {
126
        return readLong(len, true);
1✔
127
    }
128

129
    public int readInt(int length, boolean littleEndian) throws IOException {
130
        int r = 0;
1✔
131
        for (int i = 0; i < length; ++i) {
1✔
132
            final int v = this.read();
1✔
133
            if (littleEndian) {
1✔
134
                r |= (v << (i << 3));
1✔
135
            } else {
136
                r = (r << 8) | v;
1✔
137
            }
138
        }
139
        int c;
140
        return r << (c = (4 - length << 3)) >> c;
1✔
141
    }
142

143
    public long readUInt(int length) throws IOException {
144
        return readUInt(length, true);
1✔
145
    }
146

147
    public long readUInt(int length, boolean littleEndian) throws IOException {
148
        return readInt(length, littleEndian) & 0xFFFFFFFFL;
1✔
149
    }
150

151
    public int readInt(byte[] bytes) {
152
        return readInt(bytes, true);
1✔
153
    }
154

155
    public int readInt(byte[] bytes, boolean littleEndian) {
156
        int r = 0;
1✔
157
        int length = bytes.length;
1✔
158
        for (int i = 0; i < length; ++i) {
1✔
159
            final int v = bytes[i] & 0xFF;
1✔
160
            if (littleEndian) {
1✔
161
                r |= (v << (i << 3));
1✔
162
            } else {
163
                r = (r << 8) | v;
×
164
            }
165
        }
166
        int c;
167
        return r << (c = (4 - length << 3)) >> c;
1✔
168
    }
169

170
    public long readLong(int length, boolean littleEndian) throws IOException {
171
        long r = 0;
1✔
172
        for (int i = 0; i < length; ++i) {
1✔
173
            final long v = this.read();
1✔
174
            if (littleEndian) {
1✔
175
                r |= (v << (i << 3));
1✔
176
            } else {
177
                r = (r << 8) | v;
1✔
178
            }
179
        }
180
        return r;
1✔
181
    }
182

183
    public String readString(int len) throws IOException {
184
        return Strings.toString(readBytes(len).first());
1✔
185
    }
186

187
    public String readString(int len, Charset charset) throws IOException {
188
        return Strings.toString(readBytes(len).first(), charset);
×
189
    }
190

191
    @Override
192
    public int read() throws IOException {
193
        if (head >= tail) fill();
1✔
194
        if (mark) markLen += 1;
1✔
195
        byte b = buf[head++];
1✔
196
        notify(b);
1✔
197
        return b & 0xff;
1✔
198
    }
199

200
    public long read(ByteArray bytes, long offset, long len) throws IOException {
201
        long total = len;
1✔
202
        long index = offset;
1✔
203
        while (total > 0) {
1✔
204
            int available = tail - head;
1✔
205
            if (available >= total) {
1✔
206
                ByteArray.arraycopy(new ByteArray(buf), head, bytes, index, total);
1✔
207
                head += total;
1✔
208
                break;
1✔
209
            } else {
210
                ByteArray.arraycopy(new ByteArray(buf), head, bytes, index, available);
1✔
211
                index += available;
1✔
212
                total -= available;
1✔
213
                fill();
1✔
214
            }
215
        }
1✔
216
        for (byte[] b : bytes) {
1✔
217
            notify(b);
1✔
218
        }
1✔
219
        return len;
1✔
220
    }
221

222
    @Override
223
    public int read(byte[] b) throws IOException {
224
        return read(b, 0, b.length);
×
225
    }
226

227
    @Override
228
    public int read(byte[] b, int off, int len) throws IOException {
229
        return (int) read(new ByteArray(b), off, len);
×
230
    }
231

232
    @Override
233
    public int available() throws IOException {
234
        return tail - head + in.available();
×
235
    }
236

237
    public long skip(long len, boolean notify) throws IOException {
238
        long total = len;
1✔
239
        while (total > 0) {
1✔
240
            int available = tail - head;
1✔
241
            if (available >= total) {
1✔
242
                if (notify) notify(Arrays.copyOfRange(buf, head, head + (int) total));
1✔
243
                head += total;
1✔
244
                break;
1✔
245
            } else {
246
                if (notify) notify(Arrays.copyOfRange(buf, head, tail));
1✔
247
                total -= available;
1✔
248
                fill();
1✔
249
            }
250
        }
1✔
251
        return len;
1✔
252
    }
253

254
    @Override
255
    public long skip(long len) throws IOException {
256
        return skip(len, true);
1✔
257
    }
258

259
    @Override
260
    public void close() throws IOException {
261
        in.close();
1✔
262
    }
1✔
263

264
    protected void fill() throws IOException {
265
        tail = in.read(buf, 0, buf.length);
1✔
266
        if (tail == -1) throw new EOFException("end of file or end of stream.");
1✔
267
        total += tail;
1✔
268
        head = 0;
1✔
269
    }
1✔
270
}
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