@SuppressWarnings("SleepWhileInLoop") private void sleepUntilReadWouldBeNonBlocking() throws IOException { // this is the thread that would be blocked on the read call this.readThreadRef.set(Thread.currentThread()); try { while (this.available() == 0) { try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted while waiting for data"); } } } finally { this.readThreadRef.set(null); } }
@Override public int read(byte[] b, int off, int len) throws IOException { sleepUntilReadWouldBeNonBlocking(); return super.read(b, off, len); }
final InputStream is = (pipeInput != null ? new InterruptibleInputStream(pipeInput.stream()) : null); final OutputStream os = (pipeOutput != null ? pipeOutput.stream() : new NullOutputStream()); final OutputStream es = (pipeErrorToOutput ? os : (pipeError != null ? pipeError.stream() : new NullOutputStream()));
@Override public int read(byte[] b) throws IOException { sleepUntilReadWouldBeNonBlocking(); return super.read(b); }
@SuppressWarnings("SleepWhileInLoop") private void sleepUntilReadWouldBeNonBlocking() throws IOException { // this is the thread that would be blocked on the read call this.readThreadRef.set(Thread.currentThread()); try { while (this.available() == 0) { try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted while waiting for data"); } } } finally { this.readThreadRef.set(null); } }
@Override public int read(byte[] b, int off, int len) throws IOException { sleepUntilReadWouldBeNonBlocking(); return super.read(b, off, len); }
@Override public int read() throws IOException { sleepUntilReadWouldBeNonBlocking(); return super.read(); }
@Override public int read(byte[] b) throws IOException { sleepUntilReadWouldBeNonBlocking(); return super.read(b); }
@Override public int read() throws IOException { sleepUntilReadWouldBeNonBlocking(); return super.read(); }