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

package io.sentry.config;

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

final class FilesystemPropertiesLoader implements PropertiesLoader
{
    @NotNull
    private final String filePath;
    @NotNull
    private final ILogger logger;
    private boolean logNonExisting;
    
    public FilesystemPropertiesLoader(@NotNull final String filePath, @NotNull final ILogger logger) {
        this(filePath, logger, true);
    }
    
    public FilesystemPropertiesLoader(@NotNull final String filePath, @NotNull final ILogger logger, final boolean logNonExisting) {
        this.filePath = filePath;
        this.logger = logger;
        this.logNonExisting = logNonExisting;
    }
    
    @Nullable
    @Override
    public Properties load() {
        try {
            final File f = new File(this.filePath.trim());
            if (f.isFile() && f.canRead()) {
                try (final InputStream is = new BufferedInputStream(new FileInputStream(f))) {
                    final Properties properties = new Properties();
                    properties.load(is);
                    return properties;
                }
            }
            if (!f.isFile()) {
                if (this.logNonExisting) {
                    this.logger.log(SentryLevel.ERROR, "Failed to load Sentry configuration since it is not a file or does not exist: %s", this.filePath);
                }
            }
            else if (!f.canRead()) {
                this.logger.log(SentryLevel.ERROR, "Failed to load Sentry configuration since it is not readable: %s", this.filePath);
            }
        }
        catch (final Throwable e) {
            this.logger.log(SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", this.filePath);
            return null;
        }
        return null;
    }
}
