code: public int read() throws IOException {
      while (true) {
        lockR.lock();
        try {
          if (availableCount.get() > 0) {
            // as long as there is available data
            // serve it even if closed
            int b = bytes[readCursor] & 0xFF;
            incReadCursor(1);
            availableCount.decrementAndGet();
            totalRead++;
            return b;
          } else if (closed){
            // when no bytes are left and buffer is closed
            // return -1
            return -1;
          }
        } finally {
          lockR.unlock();
        }
        sleep(1);
      }
    }
docs: Read a single byte.
  Blocks until data is available, or fail if buffer is closed.