Skip to content

Commit da689c7

Browse files
committed
Improving inputStream reading based on PR comment
1 parent 0a8b280 commit da689c7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/storage/files/reader/DelimitedProtoStreamReader.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ public byte[] readNext() throws IOException {
2525
return null;
2626
}
2727
byte[] bytes = new byte[itemSize];
28-
if (inputStream.read(bytes) <= 0) {
29-
return null;
28+
int offset = 0;
29+
int readCt;
30+
do {
31+
readCt = inputStream.read(bytes, offset, itemSize - offset);
32+
offset += readCt;
33+
} while (readCt != -1 && offset < itemSize);
34+
if (offset != itemSize) {
35+
return null; // unable to read the whole item correctly
3036
}
3137
return bytes;
3238
}

0 commit comments

Comments
 (0)