Added ProtocolManager class
This commit is contained in:
parent
a8dcd6e9fd
commit
2f92de92fc
48
src/main/java/Main/ProtocolManager.java
Normal file
48
src/main/java/Main/ProtocolManager.java
Normal file
@ -0,0 +1,48 @@
|
||||
package Main;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
|
||||
public class ProtocolManager {
|
||||
Reader in;
|
||||
Writer out;
|
||||
|
||||
public ProtocolManager(Reader in, Writer out) {
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
void sendMessage(String message) throws IOException {
|
||||
ProtocolMessage packet = new ProtocolMessage(message);
|
||||
packet.sendToStream(out);
|
||||
}
|
||||
|
||||
void sendMessage(byte[] message) throws IOException {
|
||||
ProtocolMessage packet = new ProtocolMessage(Utils.bytesToHex(message));
|
||||
packet.sendToStream(out);
|
||||
}
|
||||
|
||||
void sendMessage(char[] message) throws IOException {
|
||||
ProtocolMessage packet = new ProtocolMessage(new String(message));
|
||||
packet.sendToStream(out);
|
||||
}
|
||||
|
||||
String getMessageStr() throws IOException {
|
||||
ProtocolMessage packet = new ProtocolMessage();
|
||||
packet.readFromStream(in);
|
||||
return new String(packet.getMessage());
|
||||
}
|
||||
|
||||
byte[] getMessageBytes() throws IOException {
|
||||
ProtocolMessage packet = new ProtocolMessage();
|
||||
packet.readFromStream(in);
|
||||
return Utils.stringToBytes(String.valueOf(packet.getMessage()));
|
||||
}
|
||||
|
||||
char[] getMessageChar() throws IOException {
|
||||
ProtocolMessage packet = new ProtocolMessage();
|
||||
packet.readFromStream(in);
|
||||
return packet.getMessage();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user