package in.co.waghmare;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * borrowed code from https://dzone.com/articles/unleash-power-java-8-stream
 * Created by ashishw on 10/1/16.
 */
public class File {

    public static List<String> getLines(String fileName) {
        BufferedReader bufferedReader = null;
        String fullPath = "";
        try {
            Path path = Paths.get("src/test/resources", fileName);
            fullPath = path.toFile().getAbsolutePath();
            bufferedReader = Files.newBufferedReader(path, StandardCharsets.ISO_8859_1);
            return bufferedReader.lines()
                    .collect(Collectors.toList());
        } catch (IOException exception) {
            System.out.printf("Error occurred while trying to read the file %s", fullPath);
            System.exit(0);
        }
        return Collections.emptyList();
    }
}
