mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
fix potential issues in the CountingDataInputStream
This commit is contained in:
@@ -44,14 +44,14 @@ public class CountingDataInputStream extends DataInputStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NotNull byte[] b, int off, int len) throws IOException {
|
||||
public int read(byte @NotNull [] b, int off, int len) throws IOException {
|
||||
int i = in.read(b, off, len);
|
||||
count(i);
|
||||
if (i != -1) count(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
private void count(int i) {
|
||||
count += i;
|
||||
count = Math.addExact(count, i);
|
||||
if (mark == -1)
|
||||
return;
|
||||
|
||||
@@ -69,6 +69,12 @@ public class CountingDataInputStream extends DataInputStream {
|
||||
public synchronized void mark(int readlimit) {
|
||||
if (!in.markSupported()) return;
|
||||
in.mark(readlimit);
|
||||
if (readlimit <= 0) {
|
||||
mark = -1;
|
||||
markLimit = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
mark = count;
|
||||
markLimit = readlimit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user