-
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
7 changed files
with
81 additions
and
10 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 |
---|---|---|
|
@@ -19,6 +19,4 @@ | |
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ConfigParser; | ||
import java.io.*; | ||
import java.nio.charset.Charset; | ||
|
||
public class ConfigParser extends Parser { | ||
@Override | ||
public void command(File file) { | ||
switch (file.getName()){ | ||
case ("server.conf"): | ||
new ServerObject(file).readFile(); | ||
break; | ||
case ("client.conf"): | ||
new ClientObject(); | ||
break; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
File server = new File(ConfigParser.class.getClassLoader().getResource("server.conf").getFile()); | ||
System.out.println(server.getAbsoluteFile()); | ||
|
||
new ConfigParser().command(server); | ||
} | ||
} | ||
class ServerObject{ | ||
File file; | ||
|
||
public ServerObject(File file) { | ||
this.file = file; | ||
} | ||
|
||
public void readFile(){ | ||
try(InputStream in = new FileInputStream(file); | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()){ | ||
byte[] buf = new byte [1024]; | ||
int len; | ||
while ((len = in.read()) > 0){ | ||
byteArrayOutputStream.write(buf, 0, len); | ||
} | ||
String str = new String(byteArrayOutputStream.toByteArray(), Charset.forName("UTF-8")); | ||
System.out.println(str); | ||
}catch (FileNotFoundException e){ | ||
e.getMessage(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
class ClientObject{ | ||
|
||
} |
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,9 @@ | ||
package ConfigParser; | ||
|
||
import java.io.File; | ||
|
||
abstract public class Parser{ | ||
public abstract void command(File file); | ||
// public abstract void writeJSONFile(File file); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
port => 8411; |