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

org.rx.io.CrudFile Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.io;

import org.apache.commons.io.FilenameUtils;
import org.rx.core.Linq;
import org.rx.core.Strings;

import java.io.InputStream;

public interface CrudFile {
    default boolean isDirectoryPath(String path) {
        if (Strings.isEmpty(path)) {
            return false;
        }

        char ch = path.charAt(path.length() - 1);
        return ch == '/' || ch == '\\' || Strings.isEmpty(FilenameUtils.getExtension(path));
    }

    default String getDirectoryPath(String path) {
        return FilenameUtils.getFullPath(path);
    }

    default String padDirectoryPath(String path) {
        if (Strings.isEmpty(path)) {
            return Strings.EMPTY;
        }

        char ch = path.charAt(path.length() - 1);
        if (ch == '/' || ch == '\\') {
            return path;
        }
        char separatorChar = path.lastIndexOf('\\') != -1 ? '\\' : '/';
        return path + separatorChar;
    }

    String createDirectory(String path);

    Linq listDirectories(String directoryPath, boolean recursive);

    void saveFile(String filePath, InputStream in);

    Linq listFiles(String directoryPath, boolean recursive);

    boolean exists(String path);

    void delete(String path);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy