From 7541eb2d71b0267062d8a052131f930f63995228 Mon Sep 17 00:00:00 2001 From: jakebman-charter <42015254+jakebman-charter@users.noreply.github.com> Date: Thu, 14 Feb 2019 14:35:00 -0700 Subject: [PATCH] Prevent double-read of file If the first .read() call completed before the while loop begins, multiple async reads would be scheduled. Removing the loop prevents this. --- src/main/java/rsb/io/Asynchronous.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/rsb/io/Asynchronous.java b/src/main/java/rsb/io/Asynchronous.java index 08ca51f..d6c4026 100644 --- a/src/main/java/rsb/io/Asynchronous.java +++ b/src/main/java/rsb/io/Asynchronous.java @@ -38,10 +38,6 @@ public void read(File file, Consumer c, Runnable finished) throws IOExcep Collections.singleton(StandardOpenOption.READ), this.executorService); // <2> ByteBuffer buffer = ByteBuffer.allocate(FileCopyUtils.BUFFER_SIZE); this.fileChannel.read(buffer, position, buffer, this); // <3> - while (this.bytesRead > 0) { - this.position = this.position + this.bytesRead; - this.fileChannel.read(buffer, this.position, buffer, this); - } } @Override