X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fio%2FTimeoutInputStream.java;h=70faff4eabaa0f932352b1886ea5651bfc424ac9;hb=c4cefaa04ec122fc02efb6542451a31fdf722c32;hp=d65426261ed3df9e587b62135d7c55e0cd618197;hpb=615a0d99fd0aa4437116dd083147f9150d5e6527;p=fanfix.git diff --git a/src/jexer/io/TimeoutInputStream.java b/src/jexer/io/TimeoutInputStream.java index d654262..70faff4 100644 --- a/src/jexer/io/TimeoutInputStream.java +++ b/src/jexer/io/TimeoutInputStream.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -179,8 +179,11 @@ public class TimeoutInputStream extends InputStream { // available. If not, we throw ReadTimeoutException. long checkTime = System.currentTimeMillis(); while (stream.available() == 0) { - long now = System.currentTimeMillis(); + if (remaining > 0) { + return (b.length - remaining); + } + long now = System.currentTimeMillis(); synchronized (this) { if ((now - checkTime > timeoutMillis) || (cancel == true)) { if (cancel == true) { @@ -241,7 +244,7 @@ public class TimeoutInputStream extends InputStream { if (timeoutMillis == 0) { // Block on the read(). - return stream.read(b); + return stream.read(b, off, len); } int remaining = len; @@ -257,6 +260,10 @@ public class TimeoutInputStream extends InputStream { // available. If not, we throw ReadTimeoutException. long checkTime = System.currentTimeMillis(); while (stream.available() == 0) { + if (remaining > 0) { + return (len - remaining); + } + long now = System.currentTimeMillis(); synchronized (this) { if ((now - checkTime > timeoutMillis) || (cancel == true)) {