summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/util/ResourceLoader.java
blob: 37cf5b3438a7a99318116b3a795a6b4e9ae066c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.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 {
			return Files.lines(Paths.get(fle.toURI())).toArray(sze -> new String[sze]);
		} catch (IOException | URISyntaxException ioex) {
			Errors.inst.printError(EK_MISC_IOEX, fle.toString());
		}

		return null;
	}
}