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

io.bdeploy.bhive.op.ImportFileOperation Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
package io.bdeploy.bhive.op;

import static io.bdeploy.common.util.RuntimeAssert.assertNotNull;

import java.nio.file.Files;
import java.nio.file.Path;

import io.bdeploy.bhive.BHive;
import io.bdeploy.bhive.model.ObjectId;
import io.bdeploy.bhive.model.Tree;
import io.bdeploy.bhive.objects.ObjectDatabase;

/**
 * Import a single {@link Path} into the {@link ObjectDatabase}. Useful mainly
 * when building artificial {@link Tree}.
 */
public class ImportFileOperation extends BHive.TransactedOperation {

    private Path file;

    @Override
    public ObjectId callTransacted() throws Exception {
        assertNotNull(file, "File to import not set");
        return getObjectManager().db(x -> x.addObject(file));
    }

    /**
     * Set the {@link Path} to import from. Must be an existing file.
     */
    public ImportFileOperation setFile(Path file) {
        if (!Files.isRegularFile(file)) {
            throw new IllegalArgumentException("File does not exist: " + file);
        }
        this.file = file;
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy