@Test public void testLoadFromConfig () throws IOException { ServerManager.getInstance().loadFromConfig(new File("../data/config/servers.json")); assertEquals(true, ServerManager.getInstance().listServers().size() > 0); }
public void loadFromConfig (File config) throws IOException { if (!config.exists()) { throw new IllegalStateException("server config file doesnt exists: " + config.getAbsolutePath()); } list.clear(); String content = FileUtils.readFile(config.getAbsolutePath(), StandardCharsets.UTF_8); JSONObject json = new JSONObject(content); JSONArray servers = json.getJSONArray("servers"); for (int i = 0; i < servers.length(); i++) { JSONObject server = servers.getJSONObject(i); String ip = server.getString("ip"); int port = server.getInt("port"); String title = server.getString("title"); String description = server.getString("description"); boolean online = SocketUtils.checkRemoteTCPPort(ip, port, 500); Server obj = new Server(ip, port, title, description, online); list.add(obj); } }
ServerManager { public void loadFromConfig (File config) throws IOException { if (!config.exists()) { throw new IllegalStateException("server config file doesnt exists: " + config.getAbsolutePath()); } list.clear(); String content = FileUtils.readFile(config.getAbsolutePath(), StandardCharsets.UTF_8); JSONObject json = new JSONObject(content); JSONArray servers = json.getJSONArray("servers"); for (int i = 0; i < servers.length(); i++) { JSONObject server = servers.getJSONObject(i); String ip = server.getString("ip"); int port = server.getInt("port"); String title = server.getString("title"); String description = server.getString("description"); boolean online = SocketUtils.checkRemoteTCPPort(ip, port, 500); Server obj = new Server(ip, port, title, description, online); list.add(obj); } } }
ServerManager { public void loadFromConfig (File config) throws IOException { if (!config.exists()) { throw new IllegalStateException("server config file doesnt exists: " + config.getAbsolutePath()); } list.clear(); String content = FileUtils.readFile(config.getAbsolutePath(), StandardCharsets.UTF_8); JSONObject json = new JSONObject(content); JSONArray servers = json.getJSONArray("servers"); for (int i = 0; i < servers.length(); i++) { JSONObject server = servers.getJSONObject(i); String ip = server.getString("ip"); int port = server.getInt("port"); String title = server.getString("title"); String description = server.getString("description"); boolean online = SocketUtils.checkRemoteTCPPort(ip, port, 500); Server obj = new Server(ip, port, title, description, online); list.add(obj); } } ServerManager(); }
ServerManager { public void loadFromConfig (File config) throws IOException { if (!config.exists()) { throw new IllegalStateException("server config file doesnt exists: " + config.getAbsolutePath()); } list.clear(); String content = FileUtils.readFile(config.getAbsolutePath(), StandardCharsets.UTF_8); JSONObject json = new JSONObject(content); JSONArray servers = json.getJSONArray("servers"); for (int i = 0; i < servers.length(); i++) { JSONObject server = servers.getJSONObject(i); String ip = server.getString("ip"); int port = server.getInt("port"); String title = server.getString("title"); String description = server.getString("description"); boolean online = SocketUtils.checkRemoteTCPPort(ip, port, 500); Server obj = new Server(ip, port, title, description, online); list.add(obj); } } ServerManager(); void loadFromConfig(File config); static ServerManager getInstance(); List<Server> listServers(); }
ServerManager { public void loadFromConfig (File config) throws IOException { if (!config.exists()) { throw new IllegalStateException("server config file doesnt exists: " + config.getAbsolutePath()); } list.clear(); String content = FileUtils.readFile(config.getAbsolutePath(), StandardCharsets.UTF_8); JSONObject json = new JSONObject(content); JSONArray servers = json.getJSONArray("servers"); for (int i = 0; i < servers.length(); i++) { JSONObject server = servers.getJSONObject(i); String ip = server.getString("ip"); int port = server.getInt("port"); String title = server.getString("title"); String description = server.getString("description"); boolean online = SocketUtils.checkRemoteTCPPort(ip, port, 500); Server obj = new Server(ip, port, title, description, online); list.add(obj); } } ServerManager(); void loadFromConfig(File config); static ServerManager getInstance(); List<Server> listServers();  }