diff --git a/src/main/java/org/ultramine/server/util/Resources.java b/src/main/java/org/ultramine/server/util/Resources.java new file mode 100644 index 0000000..549a077 --- /dev/null +++ b/src/main/java/org/ultramine/server/util/Resources.java @@ -0,0 +1,34 @@ +package org.ultramine.server.util; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; + +public class Resources +{ + public static InputStream getAsStream(String path) + { + return Resources.class.getResourceAsStream(path); + } + + public static String getAsString(String path) + { + InputStream is = getAsStream(path); + if(is == null) + throw new RuntimeException("Requested resource not found: " + path); + try + { + return IOUtils.toString(is, Charsets.UTF_8); + } + catch(IOException e) + { + throw new RuntimeException("Failed to load resource: " + path, e); + } + finally + { + IOUtils.closeQuietly(is); + } + } +}