Archived
0

Zond: перезагрузка настроек

This commit is contained in:
2017-06-17 14:11:10 +03:00
parent 14b3f46b50
commit 4c410cb7e7
3 changed files with 28 additions and 22 deletions

View File

@@ -4,8 +4,7 @@
*/
package asys.zond;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.Properties;
public class Config {
@@ -26,6 +25,25 @@ public class Config {
}
}
void load() throws IOException {
File zondPropertiesFile = new File("zond.properties");
if (!zondPropertiesFile.exists()) {
InputStream stream = Config.class.getResourceAsStream("/zond.properties");
FileOutputStream fos = new FileOutputStream(zondPropertiesFile);
byte[] buff = new byte[128];
int len;
while ((len = stream.read(buff)) > 0) {
fos.write(buff, 0, len);
}
fos.flush();
fos.close();
}
FileInputStream fis = new FileInputStream(zondPropertiesFile);
load(fis);
fis.close();
}
public String getString(String key) {
return properties.getProperty(key);
}

View File

@@ -25,7 +25,7 @@ public class Main {
private void start(String[] args) {
try {
loadConfig();
Config.getInstance().load();
} catch (IOException e) {
e.printStackTrace();
System.exit(-2);
@@ -54,23 +54,4 @@ public class Main {
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(stdout);
executor.setStreamHandler(pumpStreamHandler);
}
private void loadConfig() throws IOException {
File zondPropertiesFile = new File("zond.properties");
if (!zondPropertiesFile.exists()) {
InputStream stream = Main.class.getResourceAsStream("/zond.properties");
FileOutputStream fos = new FileOutputStream(zondPropertiesFile);
byte[] buff = new byte[65536];
int len;
while ((len = stream.read(buff)) > 0) {
fos.write(buff, 0, len);
}
fos.flush();
fos.close();
}
FileInputStream fis = new FileInputStream(zondPropertiesFile);
Config.getInstance().load(fis);
fis.close();
}
}

View File

@@ -65,6 +65,13 @@ public class ZondCommandHandler implements CommandHandler {
Connector.getInstance().startReconnect();
} else if (line.equalsIgnoreCase("disconnect")) {
Connector.getInstance().shutdown();
} else if (line.equalsIgnoreCase("reload")) {
Shell.getInstance().getOutput().println("Reload config");
try {
Config.getInstance().load();
} catch (IOException e) {
e.printStackTrace();
}
}
}