package com.crowdin.cli.utils.file;

import com.crowdin.cli.utils.MessageSource;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;
import java.util.ResourceBundle;


public class FileReader {

    private static final ResourceBundle RESOURCE_BUNDLE = MessageSource.RESOURCE_BUNDLE;

    private static final String DEFAULT_CONFIG_FILE_NAME = "crowdin.yml";

    private static final String YAML_EXTENSION = ".yaml";

    private static final String YML_EXTENSION = ".yml";

    public Map<String, Object> readCliConfig(File fileCfg) {
        if (fileCfg == null) {
            throw new NullPointerException("FileReader.readCliConfig has null args");
        }
        if (!(fileCfg.getName().endsWith(YAML_EXTENSION) || fileCfg.getName().endsWith(YML_EXTENSION))) {
            System.out.println("WARN: file with name '" + fileCfg.getAbsolutePath() + "' has different type from YAML");
        }

        Yaml yaml = new Yaml();
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(fileCfg);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(RESOURCE_BUNDLE.getString("error.configuration_file_not_exist"));
        }
        Map<String, Object> result = null;
        try {
            result = (Map<String, Object>) yaml.load(inputStream);
        } catch (Exception e) {
            throw new RuntimeException(RESOURCE_BUNDLE.getString("error.reading_configuration_file"), e);
        }
        return result;
    }
}
@@ -126,110 +126,9 @@
 .io.
-File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.InputStream
+*
 ;%0Aim
@@ -956,16 +956,21 @@
         
+try (
 InputStr
@@ -992,62 +992,90 @@
  = n
-ull;%0A        try %7B%0A            inputStream = new FileI
+ew FileInputStream(fileCfg))%7B%0A            return (Map%3CString, Object%3E) yaml.load(i
 nput
@@ -1080,24 +1080,16 @@
 utStream
-(fileCfg
 );%0A     
@@ -1236,142 +1236,8 @@
 ));%0A
-        %7D%0A        Map%3CString, Object%3E result = null;%0A        try %7B%0A            result = (Map%3CString, Object%3E) yaml.load(inputStream);%0A
     
@@ -1370,16 +1370,16 @@
 %22), e);%0A
+
         
@@ -1384,31 +1384,8 @@
   %7D%0A
-        return result;%0A
     

Fix old bug - close stream after reading