Add 'src/jexer/' from commit 'cf01c92f5809a0732409e280fb0f32f27393618d'
[nikiroo-utils.git] / src / jexer / io / TimeoutInputStream.java
index d65426261ed3df9e587b62135d7c55e0cd618197..3d8cdb0312494293b5e90bdeee39c5f21b32f659 100644 (file)
@@ -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) {
@@ -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)) {