// 
// Decompiled by Procyon v0.6.0
// 

package io.sentry.config;

import java.io.IOException;
import io.sentry.SentryLevel;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.util.Properties;
import io.sentry.util.ClassLoaderUtils;
import org.jetbrains.annotations.Nullable;
import io.sentry.ILogger;
import org.jetbrains.annotations.NotNull;

final class ClasspathPropertiesLoader implements PropertiesLoader
{
    @NotNull
    private final String fileName;
    @NotNull
    private final ClassLoader classLoader;
    @NotNull
    private final ILogger logger;
    
    public ClasspathPropertiesLoader(@NotNull final String fileName, @Nullable final ClassLoader classLoader, @NotNull final ILogger logger) {
        this.fileName = fileName;
        this.classLoader = ClassLoaderUtils.classLoaderOrDefault(classLoader);
        this.logger = logger;
    }
    
    public ClasspathPropertiesLoader(@NotNull final ILogger logger) {
        this("sentry.properties", ClasspathPropertiesLoader.class.getClassLoader(), logger);
    }
    
    @Nullable
    @Override
    public Properties load() {
        try (final InputStream inputStream = this.classLoader.getResourceAsStream(this.fileName)) {
            if (inputStream != null) {
                try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
                    final Properties properties = new Properties();
                    properties.load(bufferedInputStream);
                    return properties;
                }
                if (inputStream != null) {
                    inputStream.close();
                }
            }
        }
        catch (final IOException e) {
            this.logger.log(SentryLevel.ERROR, e, "Failed to load Sentry configuration from classpath resource: %s", this.fileName);
            return null;
        }
        return null;
    }
}
