All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mike10004.vhs.bmp.TempScratchDirProvider Maven / Gradle / Ivy

There is a newer version: 0.32
Show newest version
package io.github.mike10004.vhs.bmp;

import java.io.IOException;
import java.nio.file.Path;

import static java.util.Objects.requireNonNull;

class TempScratchDirProvider implements ScratchDirProvider {

    private final Path parent;
    private final String prefix;

    public TempScratchDirProvider(Path parent, String prefix) {
        this.parent = requireNonNull(parent);
        requireNonNull(prefix);
        if (prefix.length() < 6) {
            prefix += "scratch";
        }
        this.prefix = prefix;
    }

    @Override
    public Scratch createScratchDir() throws IOException {
        //noinspection ResultOfMethodCallIgnored
        parent.toFile().mkdirs();
        if (!parent.toFile().isDirectory()) {
            throw new IOException(parent + " is not a directory and directory could not be created there");
        }
        Path dir = java.nio.file.Files.createTempDirectory(parent, prefix);
        return new TempScratch(dir);
    }

    private static class TempScratch implements Scratch {

        private final Path root;

        private TempScratch(Path root) {
            this.root = requireNonNull(root);
        }

        @Override
        public Path getRoot() {
            return root;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy