summaryrefslogtreecommitdiff
path: root/base/src/bjc/dicelang/util
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-25 12:10:14 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-25 12:10:14 -0300
commit7bda9de511a5642efb297eae98c6ea7c42b27754 (patch)
treedff1aa772b9ac088c5bd07b8d10d944cbff89f96 /base/src/bjc/dicelang/util
parentf028ea6dc555fc5192a96b00b8e96e90dbf6de55 (diff)
Start switch to maven modules
Diffstat (limited to 'base/src/bjc/dicelang/util')
-rw-r--r--base/src/bjc/dicelang/util/ResourceLoader.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/base/src/bjc/dicelang/util/ResourceLoader.java b/base/src/bjc/dicelang/util/ResourceLoader.java
new file mode 100644
index 0000000..db5c6fc
--- /dev/null
+++ b/base/src/bjc/dicelang/util/ResourceLoader.java
@@ -0,0 +1,43 @@
+package bjc.dicelang.util;
+
+import static bjc.dicelang.Errors.ErrorKey.EK_MISC_IOEX;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import bjc.dicelang.Errors;
+
+/**
+ * Load resources bundled with DiceLang.
+ *
+ * @author EVE
+ *
+ */
+public class ResourceLoader {
+ /**
+ * Loads a .help file from the data/help directory.
+ *
+ * @param name
+ * The name of the help file to load.
+ *
+ * @return The contents of the help file, or null if it could not be
+ * opened.
+ */
+ public static String[] loadHelpFile(final String name) {
+ final URL fle = ResourceLoader.class.getResource("/data/help/" + name + ".help");
+
+ try {
+ Path pth = Paths.get(fle.toURI());
+
+ return Files.lines(pth).toArray(sze -> new String[sze]);
+ } catch (IOException | URISyntaxException ioex) {
+ Errors.inst.printError(EK_MISC_IOEX, fle.toString());
+ }
+
+ return null;
+ }
+}