Exemple #1
0
  public Path uploadTo(Path folder) {
    Filename filename = new Filename(getFilename());
    filename.setName(filename.getName() + SEPARATOR + getId());
    Path result = Paths.get(folder + File.separator + filename.get());

    if (!data.isEmpty()) {
      try (BufferedOutputStream stream =
          new BufferedOutputStream(new FileOutputStream(result.toFile()))) {
        stream.write(data.getBytes());
        stream.close();
        LOGGER.info("Successfully uploaded " + result);
      } catch (Exception e) {
        result = null;
        LOGGER.error("ERROR! Failed to upload " + getFilename() + " : " + e.getMessage());
      }
    } else {
      result = null;
      LOGGER.error("ERROR! Unable to upload the empty file : " + getFilename());
    }

    return result;
  }