Skip to content

Commit

Permalink
modulus operator makes the code clearer. The awesome modulus.
Browse files Browse the repository at this point in the history
  • Loading branch information
anttivi-solita committed Aug 22, 2016
1 parent 8693208 commit a59ada9
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/test/java/fi/solita/clamav/SlowInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@
public class SlowInputStream extends InputStream {

private static long SLOW_BYTE = 1000;
private long fastBytes = SLOW_BYTE;
private long bytesAvail = 60000;
private Random r = new Random();

@Override
public int read() {
int nextByte = r.nextInt(256);
if (bytesAvail < 12000) {
fastBytes--;
if (fastBytes == 0) {
try {
Thread.sleep(80); // 80 ms sleep
} catch (Exception e) {
throw new RuntimeException(e);
}
fastBytes = SLOW_BYTE;
if ((bytesAvail < 12000) && ((bytesAvail % SLOW_BYTE) == 0)) {
try {
Thread.sleep(80); // 80 ms sleep
} catch (Exception e) {
throw new RuntimeException(e);
}
}
bytesAvail--;
Expand Down

0 comments on commit a59ada9

Please sign in to comment.