package com.iqser.red.service.persistence.management.v1.processor.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.experimental.UtilityClass;

@UtilityClass
public class ResourceLoader {

    public Set<String> load(String classpathPath) {

        URL resource = ResourceLoader.class.getClassLoader().getResource(classpathPath);
        if (resource == null) {
            throw new IllegalArgumentException("could not load classpath resource: " + classpathPath);
        }
        try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.openStream(), StandardCharsets.UTF_8))) {
            return br.lines().collect(Collectors.toSet());
        } catch (IOException e) {
            throw new IllegalArgumentException("could not load classpath resource: " + classpathPath, e);
        }

    }

}

