code: public void run() {
      try {
        while (!stop) {
          while (is.available() > 0 && !stop) {
            os.write(is.read());
          }
          os.flush();
          Thread.sleep(SLEEPING_TIME);
        }
      }
      catch (Exception e) {
        log.error("Got exception while reading/writing the stream", e);
      }
    }
docs: Copies data from the input stream to the output stream. Terminates as
  soon as the input stream is closed or an error occurs.