package org.mockserver.file;

import org.apache.commons.io.IOUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @author jamesdbloom
 */
public class FileReader {

    public static String readFileFromClassPathOrPath(String filePath) {
        try (InputStream inputStream = openStreamToFileFromClassPathOrPath(filePath)) {
            return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
        } catch (IOException ioe) {
            throw new RuntimeException("Exception while loading \"" + filePath + "\"", ioe);
        }
    }

    // used by maven plugin
    public static String readFileFromClassPathOrPath(ClassLoader classLoader, String filePath) {
        try (InputStream inputStream = openStreamToFileFromClassPathOrPath(classLoader, filePath)) {
            return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
        } catch (IOException ioe) {
            throw new RuntimeException("Exception while loading \"" + filePath + "\"", ioe);
        }
    }

    public static InputStream openStreamToFileFromClassPathOrPath(String filename) throws FileNotFoundException {
        return openStreamToFileFromClassPathOrPath(FileReader.class.getClassLoader(), filename);
    }

    public static InputStream openStreamToFileFromClassPathOrPath(ClassLoader classLoader, String filename) throws FileNotFoundException {
        InputStream inputStream = classLoader.getResourceAsStream(filename);
        if (inputStream == null) {
            // load from path if not found in classpath
            inputStream = new FileInputStream(filename);
        }
        return inputStream;
    }

    public static Reader openReaderToFileFromClassPathOrPath(String filename) throws FileNotFoundException {
        return new InputStreamReader(openStreamToFileFromClassPathOrPath(filename));
    }


}

@@ -576,849 +576,173 @@
     
-// used by maven plugin%0A    public static String readFileFromClassPathOrPath(ClassLoader classLoader, String filePath) %7B%0A        try (InputStream inputStream = openStreamToFileFromClassPathOrPath(classLoader, filePath)) %7B%0A            return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());%0A        %7D catch (IOException ioe) %7B%0A            throw new RuntimeException(%22Exception while loading %5C%22%22 + filePath + %22%5C%22%22, ioe);%0A        %7D%0A    %7D%0A%0A    public static InputStream openStreamToFileFromClassPathOrPath(String filename) throws FileNotFoundException %7B%0A        return openStreamToFileFromClassPathOrPath(FileReader.class.getClassLoader(), filename);%0A    %7D%0A%0A    public static InputStream openStreamToFileFromClassPathOrPath(ClassLo
+public static InputStream openStreamToFileFromClassPathOrPath(String filename) throws FileNotFoundException %7B%0A        InputStream inputStream = FileRe
 ader
- 
+.
 class
-Loader, String filename) throws FileNotFoundException %7B%0A        InputStream inputStream = c
+.getC
 lass
@@ -747,16 +747,18 @@
 ssLoader
+()
 .getReso

remove methods no longer used by maven plugin