code: public void run() {
      log.trace("{} started.", this);
      synchronized (this) {
        // Just in case this object is reused in the future
        finished = false;
      }
  
      final byte[] buf = new byte[this.size];
  
      int length;
      try {
        while ((length = is.read(buf)) > 0) {
          os.write(buf, 0, length);
          if(flushImmediately) {
          	os.flush();
          }
        }
      } catch (Exception e) {
        // nothing to do - happens quite often with watchdog
      } finally {
        log.trace("{} finished.", this);
        if (closeWhenExhausted) {
          try {
            os.close();
          } catch (IOException e) {
            log.error("Got exception while closing exhausted output stream", e);
          }
        }
        synchronized (this) {
          finished = true;
          notifyAll();
        }
      }
    }
docs: Copies data from the input stream to the output stream. Terminates as
  soon as the input stream is closed or an error occurs.