@Override
  public Object handle(TaskExecution aTask) {
    try {
      URL url = new URL(aTask.getRequiredString("url"));
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.connect();

      if (connection.getResponseCode() / 100 == 2) {
        File downloadedFile = File.createTempFile("download-", "", null);
        int contentLength = connection.getContentLength();
        Consumer<Integer> progressConsumer =
            (p) -> eventPublisher.publishEvent(PiperEvent.of(Events.TASK_PROGRESSED,"taskId", aTask.getId(), "progress", p));

            try (BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
                OutputStream os = new ProgressingOutputStream(new FileOutputStream(downloadedFile), contentLength, progressConsumer)) {

              copy(in, os);
            }
            return downloadedFile.toString();
      }

      throw new IllegalStateException("Server returned: " + connection.getResponseCode());

    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
  }
Simple task handler which performs the download of a file (given its URL).

@since Sep 06, 2018
src/main/java/com/creactiviti/piper/taskhandler/io/Download.java