@Override
 public void write(byte b[], int off, int len) throws IOException {
   Util.checkClosed(closed);
   checkStoredException();
   pending.push(b, off, len);
   // Only do this if the push operation succeeds.
   bytesPosted.addAndGet(len);
   /* While it might be appropriate to send a notification to observers at this point, keep things
   simple and just wait until the writer thread gets around to do so instead. */
 }
 /**
  * Schedule a flush() to happen on the underlying output stream as soon as the I/O thread becomes
  * idle. This method intentionally never blocks, which is contrary to the traditional contract for
  * flush.
  */
 @Override
 public void flush() throws IOException {
   Util.checkClosed(closed);
   flushPending.set(true);
 }