Search in sources :

Example 1 with DelegatingOutputStream

use of org.apache.nifi.minifi.c2.api.util.DelegatingOutputStream in project nifi-minifi by apache.

the class FileSystemWritableConfiguration method getOutputStream.

@Override
public OutputStream getOutputStream() throws ConfigurationProviderException {
    try {
        Path parent = path.getParent();
        Files.createDirectories(parent);
        Path tmpPath = cache.resolveChildAndVerifyParent(parent, path.getFileName().toString() + "." + UUID.randomUUID().toString());
        return new DelegatingOutputStream(Files.newOutputStream(tmpPath)) {

            @Override
            public void close() throws IOException {
                super.close();
                Files.move(tmpPath, path);
            }
        };
    } catch (IOException e) {
        throw new ConfigurationProviderException("Unable to open " + path + " for writing.", e);
    }
}
Also used : Path(java.nio.file.Path) ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) IOException(java.io.IOException) DelegatingOutputStream(org.apache.nifi.minifi.c2.api.util.DelegatingOutputStream)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ConfigurationProviderException (org.apache.nifi.minifi.c2.api.ConfigurationProviderException)1 DelegatingOutputStream (org.apache.nifi.minifi.c2.api.util.DelegatingOutputStream)1