public PipedOutputStream( final int bufferSize, final SizedRecyclingSupplier<byte[]> bufferProvider, final Long globalDeadline) { this.bufferProvider = bufferProvider; buffer = bufferProvider.get(bufferSize); startIdx = 0; endIdx = 0; readerPerceivedEndIdx = 0; writerClosed = false; nrReadStreams = 0; this.globalDeadline = globalDeadline; }
@Override @WillClose public void close() { synchronized (sync) { if (!writerClosed) { try { writerClosed = true; flush(); } finally { if (nrReadStreams == 0 && availableToRead() == 0) { bufferProvider.recycle(buffer); buffer = null; } sync.notifyAll(); } } } }