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

uk.co.mruoc.FileOutputStreamConverter Maven / Gradle / Ivy

There is a newer version: 3.0.4
Show newest version
package uk.co.mruoc;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileOutputStreamConverter {

    private final FileCreator fileCreator = new FileCreator();

    public OutputStream toOutputStream(String path) {
        try {
            File file = createFileIfDoesNotExist(path);
            return new FileOutputStream(file);
        } catch (IOException e) {
            throw new TemplatePopulationException(e);
        }
    }

    private File createFileIfDoesNotExist(String stringPath) {
        Path path = Paths.get(stringPath);
        if (Files.exists(path) && Files.isRegularFile(path))
            return path.toFile();
        return fileCreator.createFile(path);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy