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

top.hendrixshen.magiclib.util.FileUtil Maven / Gradle / Ivy

package top.hendrixshen.magiclib.util;

import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.MagicLib;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Set;

public class FileUtil {
    public static @NotNull File getConfigFile(String identifier) {
        return MagicLib.getInstance().getCurrentPlatform().getConfigFolder()
                .resolve(identifier + ".json").toFile();
    }

    public static @NotNull Set getResources(String name) throws IOException {
        ClassLoader urlLoader = Thread.currentThread().getContextClassLoader();
        Set set = Sets.newHashSet();
        Enumeration urlEnumeration = urlLoader.getResources(name);

        while (urlEnumeration.hasMoreElements()) {
            try {
                set.add(urlEnumeration.nextElement().toURI());
            } catch (URISyntaxException ignore) {
            }
        }

        return set;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy