docs: public void write(byte[] buf, int offset, int length) throws IOException {
          if(buf == null) return;
          sanityCheck(buf, offset, length);
  
          lock.lock();
          try {
              if(closed) return;
              int bytes_written=0;
              while(bytes_written < length && !closed) {
  
                  if(read_pos > 0 && length - bytes_written > remaining())
                      compact();
  
                  if(remaining() > 0) {
                      int bytes_to_write=Math.min(length-bytes_written, remaining());
                      System.arraycopy(buf, offset+bytes_written, this.buf, write_pos, bytes_to_write);
                      write_pos+=bytes_to_write;
                      bytes_written+=bytes_to_write;
                      not_empty.signalAll();
                  }
                  else {
                      try {
                          not_full.await();
                      }
                      catch(InterruptedException e) {
                      }
                  }
              }
          }
          finally {
              lock.unlock();
          }
      }