Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractSitemapGenerator.toFile requires directory tree #13

Closed
cdalexndr opened this issue Nov 1, 2019 · 0 comments
Closed

AbstractSitemapGenerator.toFile requires directory tree #13

cdalexndr opened this issue Nov 1, 2019 · 0 comments

Comments

@cdalexndr
Copy link

Currently, using AbstractSitemapGenerator.toFile(file) with a file path where parent directory does not exists results in exception, so the user must manually create parent directory with file.getParentFile().mkdirs() before calling this method.

This check should be embedded inside the method to be user-friendly. For example, Apache IO commons uses:

    public static FileOutputStream openOutputStream(final File file, final boolean append) throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                throw new IOException("File '" + file + "' exists but is a directory");
            }
            if (file.canWrite() == false) {
                throw new IOException("File '" + file + "' cannot be written to");
            }
        } else {
            final File parent = file.getParentFile();
            if (parent != null) {
                if (!parent.mkdirs() && !parent.isDirectory()) {
                    throw new IOException("Directory '" + parent + "' could not be created");
                }
            }
        }
        return new FileOutputStream(file, append);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant