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

pl.allegro.tech.hermes.management.infrastructure.console.ClasspathFileConsoleConfigurationRepository Maven / Gradle / Ivy

There is a newer version: 2.8.0
Show newest version
package pl.allegro.tech.hermes.management.infrastructure.console;

import java.nio.charset.StandardCharsets;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;
import pl.allegro.tech.hermes.management.config.console.ConsoleConfigProperties;
import pl.allegro.tech.hermes.management.domain.console.ConsoleConfigurationRepository;

public class ClasspathFileConsoleConfigurationRepository implements ConsoleConfigurationRepository {

  private String configuration;

  public ClasspathFileConsoleConfigurationRepository(ConsoleConfigProperties properties) {
    configuration = loadConfiguration(properties.getLocation());
  }

  @Override
  public String getConfiguration() {
    return configuration;
  }

  private String loadConfiguration(String location) {
    try {
      ClassPathResource resource = new ClassPathResource(location);
      byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
      return new String(bytes, StandardCharsets.UTF_8);
    } catch (Exception e) {
      throw new IllegalArgumentException(
          "Error reading Hermes Console configuration from " + location, e);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy