All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.parser.util.ClasspathHelper Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc1
Show newest version
package io.swagger.parser.util;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;


public class ClasspathHelper {

    public static String loadFileFromClasspath(String location) {

        InputStream inputStream = ClasspathHelper.class.getResourceAsStream(location);

        if(inputStream == null) {
            inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(location);
        }

        if(inputStream == null) {
            inputStream = ClassLoader.getSystemResourceAsStream(location);
        }

        if(inputStream != null) {
            try {
                return IOUtils.toString(inputStream);
            } catch (IOException e) {
                throw new RuntimeException("Could not read " + location + " from the classpath", e);
            }
        }

        throw new RuntimeException("Could not find " + location + " on the classpath");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy