in daemon/src/main/java/org/mvndaemon/mvnd/daemon/DaemonInputStream.java [97:138]
public int read(byte[] b, int off, int len) throws IOException {
synchronized (datas) {
if (eof && datas.isEmpty()) {
return -1; // Return EOF if we've reached the end and no more data
}
String projectId = ProjectBuildLogAppender.getProjectId();
if (!Objects.equals(projectId, projectReading)) {
projectReading = projectId;
}
int read = 0;
while (read < len) {
if (datas.isEmpty()) {
if (eof) {
return read > 0 ? read : -1; // Exit properly on EOF
}
if (read > 0) {
break;
}
// Always notify we need input when waiting for data
startReadingFromProject.accept(projectReading, len - read);
try {
datas.wait();
} catch (InterruptedException e) {
throw new InterruptedIOException("Interrupted");
}
pos = -1;
continue;
}
byte[] curData = datas.getFirst();
if (pos >= curData.length) {
datas.removeFirst();
pos = -1;
continue;
}
if (pos < 0) {
pos = 0;
}
b[off + read++] = curData[pos++];
}
return read;
}
}