class OutputWriterHelper {

    static void moveToFile(Map<String, File> files, File outputFile, ExistingOutputPolicy existingOutputPolicy,
            TaskExecutionContext executionContext) throws IOException {
        if (outputFile.exists() && !outputFile.isFile()) {
            throw new IOException(String.format("Wrong output destination %s, must be a file.", outputFile));
        }
        if (files.size() != 1) {
            throw new IOException(
                    String.format("Wrong files map size %d, must be 1 to copy to the selected destination %s",
                            files.size(), outputFile));
        }
        for (Entry<String, File> entry : files.entrySet()) {
            moveFile(entry.getValue(), outputFile, of(existingOutputPolicy).filter(p -> p != SKIP).orElseGet(() -> {
                LOG.debug("Cannot use {} output policy for single output, replaced with {}", SKIP, FAIL);
                return FAIL;
            }), executionContext);
        }
    }

    private  OutputWriterHelper();

}