Further improved Java Docs 10 missing todos.
This commit is contained in:
@@ -29,7 +29,6 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ConnectionHandler#DATA_TYPE_CONNECT}
|
||||
*/
|
||||
public static String getDataTypeConnect() {
|
||||
@@ -37,7 +36,6 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ConnectionHandler#DATA_TYPE_CONFIRM}
|
||||
*/
|
||||
public static String getDataTypeConfirm() {
|
||||
@@ -45,7 +43,6 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ConnectionHandler#DATA_TYPE_DISCONNECT}
|
||||
*/
|
||||
public static String getDataTypeDisconnect() {
|
||||
@@ -53,7 +50,6 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ConnectionHandler#DATA_TYPE_MESSAGE
|
||||
*/
|
||||
public static String getDataTypeMessage() {
|
||||
@@ -61,7 +57,6 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ConnectionHandler#DATA_TYPE_ERROR}
|
||||
*/
|
||||
public static String getDataTypeError() {
|
||||
@@ -69,7 +64,6 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link NetworkHandler.NetworkConnection}
|
||||
*/
|
||||
public NetworkHandler.NetworkConnection<String> getConnection() {
|
||||
@@ -78,6 +72,7 @@ public abstract class ConnectionHandler {
|
||||
|
||||
/**
|
||||
* This method sets the NetworkConnection used for the server <-> client connection
|
||||
*
|
||||
* @param connection NetworkConnection used for the server <-> client connection
|
||||
*/
|
||||
protected void setConnection(NetworkHandler.NetworkConnection<String> connection) {
|
||||
@@ -85,26 +80,24 @@ public abstract class ConnectionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method reads the data when a ConnectionHandler recieves it. It tries to read out the sender, reciever, type and payload.
|
||||
* This method reads the data when a ConnectionHandler receives it. It tries to read out the sender, receiver, type and payload.
|
||||
* If the data does not contain the expected number of lines, it throws a {@link ChatProtocolException}
|
||||
* @param scanner to read data
|
||||
* @param sender of the data
|
||||
* @param reciever for the data
|
||||
* @param type of data
|
||||
* @param payload the data sent
|
||||
*
|
||||
* @param scanner to read data
|
||||
* @param sender of the data
|
||||
* @param receiver for the data
|
||||
* @param type of data
|
||||
* @param payload the data sent
|
||||
* @throws ChatProtocolException if the data does not contain the expected number of lines
|
||||
*/
|
||||
protected void processData(Scanner scanner, StringBuilder sender, StringBuilder reciever, StringBuilder type, StringBuilder payload) throws ChatProtocolException {
|
||||
protected void processData(Scanner scanner, StringBuilder sender, StringBuilder receiver, StringBuilder type, StringBuilder payload) throws ChatProtocolException {
|
||||
// parse data content
|
||||
if (scanner.hasNextLine()) {
|
||||
sender.append(scanner.nextLine());
|
||||
} else if (scanner.hasNextLine()) {
|
||||
receiver.append(scanner.nextLine());
|
||||
} else {
|
||||
throw new ChatProtocolException("No Sender found");
|
||||
}
|
||||
if (scanner.hasNextLine()) {
|
||||
reciever.append(scanner.nextLine());
|
||||
} else {
|
||||
throw new ChatProtocolException("No Reciever found");
|
||||
throw new ChatProtocolException("No Receiver found");
|
||||
}
|
||||
if (scanner.hasNextLine()) {
|
||||
type.append(scanner.nextLine());
|
||||
@@ -118,19 +111,20 @@ public abstract class ConnectionHandler {
|
||||
|
||||
/**
|
||||
* This method gets called to send data via the socket defined in the {@link NetworkHandler.NetworkConnection}
|
||||
* @param sender of the data
|
||||
*
|
||||
* @param sender of the data
|
||||
* @param receiver of the data
|
||||
* @param type of the data
|
||||
* @param payload of the data
|
||||
* @param type of the data
|
||||
* @param payload of the data
|
||||
*/
|
||||
protected void sendData(String sender, String receiver, String type, String payload) {
|
||||
if (connection.isAvailable()) {
|
||||
new StringBuilder();
|
||||
String data = new StringBuilder()
|
||||
.append(sender+"\n")
|
||||
.append(receiver+"\n")
|
||||
.append(type+"\n")
|
||||
.append(payload+"\n")
|
||||
.append(sender + "\n")
|
||||
.append(receiver + "\n")
|
||||
.append(type + "\n")
|
||||
.append(payload + "\n")
|
||||
.toString();
|
||||
try {
|
||||
connection.send(data);
|
||||
@@ -138,7 +132,7 @@ public abstract class ConnectionHandler {
|
||||
System.err.println("Connection closed: " + e.getMessage());
|
||||
} catch (EOFException e) {
|
||||
System.out.println("Connection terminated by remote");
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
System.err.println("Communication error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user