in server/src/main/java/com/epam/aidial/core/server/vertx/stream/InputStreamAdapter.java [63:111]
public synchronized int read(byte[] array, int offset, int length) throws IOException {
Objects.checkFromIndexSize(offset, length, array.length);
if (error != null) {
throw error;
}
if (current == END_PILL) {
return -1;
}
if (length == 0) {
return 0;
}
try {
int size = 0;
while (size < length) {
if (current == null) {
current = queue.take();
if (error != null) {
throw error;
}
if (current == END_PILL) {
break;
}
}
int chunk = Math.min(length - size, current.length() - position);
current.getBytes(position, position + chunk, array, offset + size);
position += chunk;
size += chunk;
if (position == current.length()) {
update(-current.length());
current = null;
position = 0;
}
}
return size == 0 ? -1 : size;
} catch (InterruptedException e) {
error = new IOException(e);
throw new IOException(error);
}
}