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

io.github.eliux.mega.cmd.MegaCmdMakeDirectory Maven / Gradle / Ivy

Go to download

Java client library that works on top of MEGAcmd to provide access to the services of Mega.nz

The newest version!
package io.github.eliux.mega.cmd;

import io.github.eliux.mega.error.MegaWrongArgumentsException;

import java.util.LinkedList;
import java.util.List;

public class MegaCmdMakeDirectory extends AbstractMegaCmdRunnerWithParams {

    private final String remotePath;

    private boolean recursively;

    private boolean errorIgnoredIfExists;

    public MegaCmdMakeDirectory(String remotePath) {
        this.remotePath = remotePath;
    }

    @Override
    public String getCmd() {
        return "mkdir";
    }

    @Override
    List cmdParams() {
        List params = new LinkedList<>();

        if (recursively) {
            params.add("-p");
        }

        params.add(getRemotePath());

        return params;
    }

    public String getRemotePath() {
        return remotePath;
    }

    public MegaCmdMakeDirectory recursively() {
        recursively = true;
        return this;
    }

    public MegaCmdMakeDirectory notRecursively() {
        recursively = false;
        return this;
    }

    public boolean isRecursively() {
        return recursively;
    }

    public boolean isErrorIgnoredIfExists() {
        return errorIgnoredIfExists;
    }

    public MegaCmdMakeDirectory ignoreErrorIfExists() {
        errorIgnoredIfExists = true;
        return this;
    }

    public MegaCmdMakeDirectory throwErrorIfExists() {
        errorIgnoredIfExists = false;
        return this;
    }

    @Override
    public void run() {
        try {
            super.run();
        } catch (MegaWrongArgumentsException ex) {
            if (!errorIgnoredIfExists) {
                throw ex;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy