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

org.qbicc.machine.tool.process.InputStreamSupplierInputSource Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.machine.tool.process;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

import io.smallrye.common.function.ExceptionFunction;

final class InputStreamSupplierInputSource extends InputSource {
    private final ExceptionFunction function;
    private final T param;

    InputStreamSupplierInputSource(final ExceptionFunction function, final T param) {
        this.function = function;
        this.param = param;
    }

    public void transferTo(final OutputDestination destination) throws IOException {
        destination.transferFrom(this);
    }

    ProcessBuilder.Redirect getInputRedirect() {
        return ProcessBuilder.Redirect.PIPE;
    }

    void writeTo(final Path path) throws IOException {
        try (InputStream is = openStream()) {
            Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);
        }
    }

    @Override
    public String toString() {
        return "";
    }

    ExceptionFunction getFunction() {
        return function;
    }

    T getParam() {
        return param;
    }

    InputStream openStream() throws IOException {
        return function.apply(param);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy