Fix buffer not being emptied

This commit is contained in:
TheMode 2021-08-09 02:05:51 +02:00
parent 1b708bc851
commit 5b8b9cab57

View File

@ -124,12 +124,15 @@ public final class BinaryBuffer {
}
public void writeChannel(WritableByteChannel channel) throws IOException {
final int count = channel.write(asByteBuffer(readerOffset, writerOffset));
if (count == -1) {
// EOS
throw new IOException("Disconnected");
var writeBuffer = asByteBuffer(readerOffset, writerOffset);
while (writeBuffer.position() != writeBuffer.limit()) {
final int count = channel.write(writeBuffer);
if (count == -1) {
// EOS
throw new IOException("Disconnected");
}
this.readerOffset += count;
}
this.readerOffset += count;
}
public void readChannel(ReadableByteChannel channel) throws IOException {