forked from vexsoftware/votifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
342 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/kryeit/votifier/config/ConfigReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.kryeit.votifier.config; | ||
|
||
|
||
import com.kryeit.votifier.utils.JSONObject; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class ConfigReader { | ||
|
||
public static String HOST; | ||
public static int PORT; | ||
public static boolean DEBUG; | ||
public static String LISTENER_FOLDER; | ||
|
||
private ConfigReader() { | ||
|
||
} | ||
|
||
public static void readFile(Path path) throws IOException { | ||
String config = readOrCopyFile(path.resolve("config.json"), "/config.json"); | ||
JSONObject configObject = new JSONObject(config); | ||
HOST = configObject.getString("host"); | ||
PORT = Integer.parseInt(configObject.getString("port")); | ||
DEBUG = configObject.getBoolean("debug"); | ||
LISTENER_FOLDER = configObject.getString("listener-folder"); | ||
} | ||
|
||
public static String readOrCopyFile(Path path, String exampleFile) throws IOException { | ||
File file = path.toFile(); | ||
if (!file.exists()) { | ||
InputStream stream = ConfigReader.class.getResourceAsStream(exampleFile); | ||
if (stream == null) throw new NullPointerException("Cannot load example file"); | ||
|
||
//noinspection ResultOfMethodCallIgnored | ||
file.getParentFile().mkdirs(); | ||
Files.copy(stream, path); | ||
} | ||
return Files.readString(path); | ||
} | ||
} |
Oops, something went wrong.