-
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
11 changed files
with
180 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
public class Client extends DimplomaApp { | ||
private static final String CLIENTCONFIG = Client.class.getClassLoader().getResource("client.conf").getFile(); | ||
private int clientPort; | ||
private String nameClient; | ||
private String server; | ||
|
||
public String getCLIENTCONFIG() { | ||
return CLIENTCONFIG; | ||
} | ||
|
||
public int getClientPort() { | ||
return clientPort; | ||
} | ||
|
||
public void setClientPort(int clientPort) { | ||
this.clientPort = clientPort; | ||
} | ||
|
||
public String getNameClient() { | ||
return nameClient; | ||
} | ||
|
||
public void setNameClient(String nameClient) { | ||
this.nameClient = nameClient; | ||
} | ||
|
||
public String getServer() { | ||
return server; | ||
} | ||
|
||
public void setServer(String server) { | ||
this.server = server; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Client client = new Client(); | ||
ParserConfigFiles parserClientFiles = new ParserConfigFiles(client); | ||
parserClientFiles.getConfig(); | ||
client.start(); | ||
} | ||
|
||
@Override | ||
void start() { | ||
System.out.println(getClientPort()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
abstract public class DimplomaApp { | ||
abstract void start(); | ||
} |
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,74 @@ | ||
import java.io.*; | ||
import java.nio.charset.Charset; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
||
class ParserConfigFiles { | ||
private DimplomaApp app; | ||
private File fileConfig; | ||
|
||
ParserConfigFiles(DimplomaApp app) { | ||
this.app = app; | ||
} | ||
|
||
void getConfig(){ | ||
if (app instanceof Server){ | ||
readServerFile((Server)app); | ||
} | ||
if (app instanceof Client){ | ||
readClientFile((Client)app); | ||
} | ||
} | ||
|
||
private void readServerFile(Server server){ | ||
fileConfig = new File(server.getSERVERCONFIG()); | ||
String configServerString = reader(fileConfig); | ||
setValue(server, configServerString); | ||
|
||
} | ||
|
||
private void readClientFile(Client client){ | ||
fileConfig = new File(client.getCLIENTCONFIG()); | ||
String configClientString = reader(fileConfig); | ||
setValue(client, configClientString); | ||
|
||
} | ||
private String reader(File file){ | ||
String str = null; | ||
try(InputStream in = new FileInputStream(file); | ||
ByteArrayOutputStream bout = new ByteArrayOutputStream()){ | ||
byte[] buf = new byte[1024]; | ||
int len; | ||
while ((len = in.read(buf)) > 0){ | ||
bout.write(buf, 0, len); | ||
str = new String(bout.toByteArray(), Charset.forName("UTF-8")); | ||
} | ||
}catch (IOException e){ | ||
e.getMessage(); | ||
} | ||
return str; | ||
} | ||
private void setValue(Client client, String string){ | ||
HashMap<String, String> configClientValues = new HashMap<>(); | ||
String[] configArray = string.split("\n"); | ||
for (String str: configArray) { | ||
String[] tempString = str.split("=>"); | ||
configClientValues.put(tempString[0], tempString[1]); | ||
} | ||
|
||
client.setClientPort(Integer.parseInt(configClientValues.get("port"))); | ||
client.setNameClient(configClientValues.get("name")); | ||
client.setServer(configClientValues.get("server")); | ||
} | ||
|
||
private void setValue(Server server, String string){ | ||
HashMap<String, String> configValues = new HashMap<>(); | ||
String[] configArray = string.split("\n"); | ||
for (String str: configArray) { | ||
String[] tempString = str.split("=>"); | ||
configValues.put(tempString[0], tempString[1]); | ||
} | ||
server.setServerPort(Integer.parseInt(configValues.get("port"))); | ||
} | ||
|
||
} |
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,36 @@ | ||
|
||
public class Server extends DimplomaApp{ | ||
private static final String SERVERCONFIG = Server.class.getClassLoader().getResource("server.conf").getFile(); | ||
private int serverPort; | ||
private static Server instances; | ||
|
||
private Server(){} | ||
|
||
public static Server getInstance(){ | ||
if (instances == null) instances = new Server(); | ||
return instances; | ||
} | ||
|
||
public String getSERVERCONFIG() { | ||
return SERVERCONFIG; | ||
} | ||
|
||
public int getServerPort() { | ||
return serverPort; | ||
} | ||
|
||
public void setServerPort(int serverPort) { | ||
this.serverPort = serverPort; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Server server = getInstance(); | ||
ParserConfigFiles serverConfig = new ParserConfigFiles(server); | ||
serverConfig.getConfig(); | ||
server.start(); | ||
} | ||
|
||
void start(){ | ||
System.out.println(getServerPort()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
name => client1; | ||
server => 127.0.0.1; | ||
port => 8411; | ||
name=>client1 | ||
server=>127.0.0.1 | ||
port=>8411 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
port => 8411; | ||
port=>8411 |
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,17 @@ | ||
file{ | ||
name=>testfile; | ||
path=>"/"; | ||
content=>"hello world"; | ||
owner=>root; | ||
group=>root; | ||
chown=>777; | ||
} | ||
package{ | ||
name=>nginx; | ||
version=>latest; | ||
dependence=>update; | ||
} | ||
command{ | ||
name=>update; | ||
exec=>apt&apt-get update || yum&yum update; | ||
} |