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,13 +124,16 @@ public final class BinaryBuffer {
} }
public void writeChannel(WritableByteChannel channel) throws IOException { public void writeChannel(WritableByteChannel channel) throws IOException {
final int count = channel.write(asByteBuffer(readerOffset, writerOffset)); var writeBuffer = asByteBuffer(readerOffset, writerOffset);
while (writeBuffer.position() != writeBuffer.limit()) {
final int count = channel.write(writeBuffer);
if (count == -1) { if (count == -1) {
// EOS // EOS
throw new IOException("Disconnected"); throw new IOException("Disconnected");
} }
this.readerOffset += count; this.readerOffset += count;
} }
}
public void readChannel(ReadableByteChannel channel) throws IOException { public void readChannel(ReadableByteChannel channel) throws IOException {
final int count = channel.read(asByteBuffer(readerOffset, capacity)); final int count = channel.read(asByteBuffer(readerOffset, capacity));