public static void verifyWritableFile()

in c3r-sdk-core/src/main/java/com/amazonaws/c3r/utils/FileUtil.java [128:143]


    public static void verifyWritableFile(final String location, final boolean overwrite) {
        if (location.isBlank()) {
            throw new C3rIllegalArgumentException("File path is empty.");
        }

        // Check if file exists and can be written to
        final Path outFile = Path.of(location);
        if (Files.exists(outFile) && !overwrite) {
            throw new C3rIllegalArgumentException(
                    "Cannot write to file `" + location + "`. File already exists and overwrite flag is false.");
        } else if (Files.isDirectory(outFile)) {
            throw new C3rIllegalArgumentException("Cannot write to file `" + location + "`. File is a directory.");
        } else if (Files.exists(outFile) && !Files.isWritable(outFile)) {
            throw new C3rIllegalArgumentException("Cannot write to file `" + location + "`. Permission denied.");
        }
    }