package com.qmth.exam.reserve.util;

import java.io.InputStream;
import java.net.URL;

public class ResourceUtil {
    public static URL getUrl(String path) {
        try {
            ClassLoader classLoader = ResourceUtil.class.getClassLoader();

            URL url = classLoader.getResource(path);
            return url;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static InputStream getStream(String path) {
        try {
            ClassLoader classLoader = ResourceUtil.class.getClassLoader();

            URL url = classLoader.getResource(path);
            return url.openStream();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String getContent(String path) {
        try {
            ClassLoader classLoader = ResourceUtil.class.getClassLoader();

            URL url = classLoader.getResource(path);
            return FileUtil.readFileContent(url.openStream());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
