@Override public int read(long timeout, boolean isPeek) throws IOException { if (closed.get()) { throw new ClosedException(); } return in.read(timeout, isPeek); }
/** * Blocks until there is new space available for buffering or the * reader is closed. * * @throws InterruptedIOException If {@link #wait()} is interrupted * @throws ClosedException If the reader was closed */ private void waitForBufferSpace() throws InterruptedIOException, ClosedException { if (!wait(writeBuffer)) { throw new ClosedException(); } }
synchronized void write(char[] cbuf, int off, int len) throws IOException { while (len > 0) { // Blocks until there is new space available for buffering or the // reader is closed. if (wait(writeBuffer, 0L) == EOF) { throw new ClosedException(); } // Copy as much characters as we can int count = Math.min(len, writeBuffer.remaining()); writeBuffer.put(cbuf, off, count); off += count; len -= count; // Update buffer states and rewind if necessary rewind(writeBuffer, readBuffer); } }
synchronized void write(byte[] cbuf, int off, int len) throws IOException { while (len > 0) { // Blocks until there is new space available for buffering or the // reader is closed. if (wait(writeBuffer, 0L) == EOF) { throw new ClosedException(); } // Copy as much characters as we can int count = Math.min(len, writeBuffer.remaining()); writeBuffer.put(cbuf, off, count); off += count; len -= count; // Update buffer states and rewind if necessary rewind(writeBuffer, readBuffer); } }
synchronized (lock) { if (!isOpen()) { throw new ClosedException("InputStreamReader is closed.");