*/
public class TimeoutInputStream extends InputStream {
+ // ------------------------------------------------------------------------
+ // Variables --------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* The wrapped stream.
*/
*/
private volatile boolean cancel = false;
- /**
- * Request that the current read() operation timeout immediately.
- */
- public synchronized void cancelRead() {
- cancel = true;
- }
+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
/**
* Public constructor, at the default timeout of 10000 millis (10
this.timeoutMillis = timeoutMillis;
}
+ // ------------------------------------------------------------------------
+ // InputStream ------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* Reads the next byte of data from the input stream.
*
"on?");
}
remaining -= rc;
- return rc;
+ if (remaining == 0) {
+ return b.length;
+ }
}
}
"available, but read() returned -1. What is going " +
"on?");
}
- return rc;
+ remaining -= rc;
+ if (remaining == 0) {
+ return len;
+ }
}
}
return stream.skip(n);
}
+ // ------------------------------------------------------------------------
+ // TimeoutInputStream -----------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Request that the current read() operation timeout immediately.
+ */
+ public synchronized void cancelRead() {
+ cancel = true;
+ }
+
}