mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Legger til en ressurslaster
This commit is contained in:
parent
4a1e974538
commit
e0e676e0fb
@ -27,12 +27,7 @@ public final class BoardLoaderUtil {
|
|||||||
* @throws IOException If the board file cannot be loaded
|
* @throws IOException If the board file cannot be loaded
|
||||||
*/
|
*/
|
||||||
public static Board loadBoard(String boardFile, List<Robot> robotList) throws IOException {
|
public static Board loadBoard(String boardFile, List<Robot> robotList) throws IOException {
|
||||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
InputStream fileStream = ResourceUtil.getResourceAsInputStream(boardFile);
|
||||||
InputStream fileStream = classloader.getResourceAsStream(boardFile);
|
|
||||||
if (fileStream == null) {
|
|
||||||
throw new IllegalArgumentException("Board file could not be loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
|
||||||
String infoLine = reader.readLine();
|
String infoLine = reader.readLine();
|
||||||
String[] infoData = infoLine.split(" ");
|
String[] infoData = infoLine.split(" ");
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package inf112.fiasko.roborally.utility;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class ResourceUtil {
|
||||||
|
private ResourceUtil() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an input stream for a given resource
|
||||||
|
* @param resourcePath The relative path from the resources folder to the resource
|
||||||
|
* @return An input stream
|
||||||
|
*/
|
||||||
|
public static InputStream getResourceAsInputStream(String resourcePath) {
|
||||||
|
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||||
|
InputStream resourceStream = classloader.getResourceAsStream(resourcePath);
|
||||||
|
if (resourceStream == null) {
|
||||||
|
throw new IllegalArgumentException("Unable to load resource.");
|
||||||
|
}
|
||||||
|
return resourceStream;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user