Petits ajustements

Remplacement des \n par System.lineseparator et utilisation de
stringbuilder pour la récupération de l'historique.
This commit is contained in:
Marino Benassai 2021-02-15 10:02:51 +01:00
parent 79ee62e6d8
commit 031da499e1
10 changed files with 27 additions and 27 deletions

View file

@ -6,7 +6,7 @@
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="C:/Program Files/Java/mysql-connector-java-8.0.22.jar"> <classpathentry kind="lib" path="C:/Program Files/Java/mysql-connector-java-8.0.22.jar" sourcepath="C:/Users/Marin/.m2/repository/mysql/mysql-connector-java/8.0.22/mysql-connector-java-8.0.22-sources.jar">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>

View file

@ -50,7 +50,7 @@ public class GestionnaireHistorique {
int rs1; int rs1;
ResultSet rs2 = null; ResultSet rs2 = null;
Connection con = null; Connection con = null;
String history = ""; StringBuilder history = new StringBuilder();
String query1 = String query1 =
"CREATE TABLE IF NOT EXISTS " + id "CREATE TABLE IF NOT EXISTS " + id
@ -75,8 +75,8 @@ public class GestionnaireHistorique {
while(rs2.next()) { while(rs2.next()) {
System.out.println("Historic SUCCESS"); System.out.println("Historic SUCCESS");
history += GestionnaireNom.instance().nomFromId(rs2.getString(2)) + ": "; //indice commence à 1 history.append(GestionnaireNom.instance().nomFromId(rs2.getString(2)) + ": "); //indice commence à 1
history += rs2.getString(3) + "\n"; history.append(rs2.getString(3) + System.lineSeparator());
} }
// à mettre dans un finally // à mettre dans un finally
@ -91,7 +91,7 @@ public class GestionnaireHistorique {
e.printStackTrace(); e.printStackTrace();
} }
return history; return history.toString();
} }

View file

@ -37,7 +37,7 @@ public class GestionnaireSessionsLocales implements Runnable{
TCPClient client = new TCPClient(gn.ipFromNom(name), PORT_REQUETE_NOUVELLE_SESSION + Integer.parseInt(gn.idFromNom(name))) ; TCPClient client = new TCPClient(gn.ipFromNom(name), PORT_REQUETE_NOUVELLE_SESSION + Integer.parseInt(gn.idFromNom(name))) ;
SessionClavardageLocale session = new SessionClavardageLocale(gn.getId(), gn.idFromNom(name), client, null); SessionClavardageLocale session = new SessionClavardageLocale(gn.getId(), gn.idFromNom(name), client, null);
this.sessions.put(gn.idFromNom(name), session); this.sessions.put(gn.idFromNom(name), session);
client.send(gn.getId()+"\n"); client.send(gn.getId()+System.lineSeparator());
System.out.print("Paramètres de session envoyée à " + gn.idFromNom(name) + "\n"); System.out.print("Paramètres de session envoyée à " + gn.idFromNom(name) + "\n");
//Lancement de la fenêtre de session //Lancement de la fenêtre de session
@ -102,7 +102,7 @@ public class GestionnaireSessionsLocales implements Runnable{
TCPClient clientEnvoi = new TCPClient(client.getAdresseCible(), PORT_REQUETE_NOUVELLE_SESSION + Integer.parseInt(idClient)); TCPClient clientEnvoi = new TCPClient(client.getAdresseCible(), PORT_REQUETE_NOUVELLE_SESSION + Integer.parseInt(idClient));
SessionClavardageLocale session = new SessionClavardageLocale(gn.getId(), idClient, clientEnvoi, client); SessionClavardageLocale session = new SessionClavardageLocale(gn.getId(), idClient, clientEnvoi, client);
this.sessions.put(idClient, session); this.sessions.put(idClient, session);
clientEnvoi.send(gn.getId()+"\n"); clientEnvoi.send(gn.getId()+System.lineSeparator());
System.out.print("Fin de la configuration de " + gn.getId() + "\n"); System.out.print("Fin de la configuration de " + gn.getId() + "\n");
System.out.println("Il y a actuellement " + sessions.size() + " session(s) ouverte(s)."); System.out.println("Il y a actuellement " + sessions.size() + " session(s) ouverte(s).");

View file

@ -26,7 +26,7 @@ public abstract class SessionClavardage {
public String toString() { public String toString() {
return "Session entre " + "this.idSource" + " et " + this.idDestination + "\n"; return "Session entre " + "this.idSource" + " et " + this.idDestination + System.lineSeparator();
} }
public String getIdSource() { public String getIdSource() {

View file

@ -61,7 +61,7 @@ public class SessionClavardageDistante extends SessionClavardage{
} }
public String toString() { public String toString() {
return "Session à distance entre " + this.getIdSource() + " et " + this.getIdDestination() + "\n"; return "Session à distance entre " + this.getIdSource() + " et " + this.getIdDestination() + System.lineSeparator();
} }

View file

@ -35,7 +35,7 @@ public class SessionClavardageLocale extends SessionClavardage{
@Override @Override
public String toString() { public String toString() {
return "Session locale entre " + this.idSource + " à l'adresse " + this.clientEmission.getAdresseSource() return "Session locale entre " + this.idSource + " à l'adresse " + this.clientEmission.getAdresseSource()
+ ", et " + this.idDestination + " à l'adresse " + this.clientEmission.getAdresseCible() + "\n"; + ", et " + this.idDestination + " à l'adresse " + this.clientEmission.getAdresseCible() + System.lineSeparator();
} }
public TCPClient getClientReception() { public TCPClient getClientReception() {

View file

@ -23,7 +23,7 @@ public class ServletResponse {
public String toString (){ public String toString (){
if (this.messageList != null) { if (this.messageList != null) {
return "Status code: " + this.statusCode +", " + this.messageList.size() + " messages reçus."; return "Status code: " + this.statusCode +", " + this.messageList.size() + " messages reçus.";
} }
else { else {
return "Status code: " + this.statusCode; return "Status code: " + this.statusCode;

View file

@ -17,7 +17,7 @@ public class Main {
//on lance le server d'écoute de cmd //on lance le server d'écoute de cmd
GestionnaireListeUtilisateur.instance().ecoute2(2001); GestionnaireListeUtilisateur.instance().ecoute2(2001);
//on crée manuellement des utilisateurs //debug //on crée manuellement des utilisateurs //debug1
GestionnaireListeUtilisateur.instance().envoie2("add$$$77$$$Moidebug$$$LocalHost$$$true"); GestionnaireListeUtilisateur.instance().envoie2("add$$$77$$$Moidebug$$$LocalHost$$$true");
//on met à jour notre liste //on met à jour notre liste

View file

@ -36,12 +36,12 @@ public class TCPClient {
this.socket = new Socket(host, port); this.socket = new Socket(host, port);
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
System.out.print("Could not find host\n"); System.out.println("Could not find host");
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
System.out.print("port= "+port+" host= "+host+"\n"); System.out.println("port= "+port+" host= "+host);
System.out.print("Could not create socket\n"); System.out.println("Could not create socket");
} }
@ -51,13 +51,13 @@ public class TCPClient {
this.textInput = new BufferedReader(new InputStreamReader(socket.getInputStream())); this.textInput = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} }
catch (IOException e) { catch (IOException e) {
System.out.print("Error while reading textInput stream\n"); System.out.println("Error while reading textInput stream");
} }
try { try {
this.textOutput = new PrintWriter(socket.getOutputStream(),true); this.textOutput = new PrintWriter(socket.getOutputStream(),true);
} }
catch (IOException e) { catch (IOException e) {
System.out.print("Error while reading textOutput stream\n"); System.out.println("Error while reading textOutput stream");
} }
this.support = new PropertyChangeSupport(this); this.support = new PropertyChangeSupport(this);
@ -72,13 +72,13 @@ public class TCPClient {
this.textInput = new BufferedReader(new InputStreamReader(socket.getInputStream())); this.textInput = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} }
catch (IOException e) { catch (IOException e) {
System.out.print("Error while reading textInput stream"); System.out.println("Error while reading textInput stream");
} }
try { try {
this.textOutput = new PrintWriter(socket.getOutputStream(),true); this.textOutput = new PrintWriter(socket.getOutputStream(),true);
} }
catch (IOException e) { catch (IOException e) {
System.out.print("Error while reading textOutput stream"); System.out.println("Error while reading textOutput stream");
} }
support = new PropertyChangeSupport(this); support = new PropertyChangeSupport(this);
} }
@ -115,7 +115,7 @@ public class TCPClient {
this.socket.close(); this.socket.close();
} }
catch (IOException e) { catch (IOException e) {
System.out.print("Error while closing connection\n"); System.out.println("Error while closing connection");
} }
@ -128,7 +128,7 @@ public class TCPClient {
this.socket = new Socket(this.adresseCible.getHostName(), port); this.socket = new Socket(this.adresseCible.getHostName(), port);
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
System.out.print("Could not find host"); System.out.println("Could not find host");
} }
} }
@ -155,10 +155,10 @@ public class TCPClient {
public static void main(String[] args) throws IOException{ public static void main(String[] args) throws IOException{
//TCPClient client = new TCPClient("LAPTOP-944OJJB9", 19999); //TCPClient client = new TCPClient("LAPTOP-944OJJB9", 19999);
TCPClient client = new TCPClient("srv-gei-tomcat.insa-toulouse.fr", 19999); TCPClient client = new TCPClient("srv-gei-tomcat.insa-toulouse.fr", 19999);
String message = "Bonjour.\n"; String message = "Bonjour.";
System.out.printf("Message envoyé: %s", message); System.out.printf("Message envoyé: %s", message);
client.send(message); client.send(message);
System.out.printf("Message reçu: %s\n", client.receive()); System.out.printf("Message reçu: %s"+System.lineSeparator(), client.receive());
client.stop(); client.stop();
} }
} }

View file

@ -54,14 +54,14 @@ public class DiscussionUI extends JFrame implements PropertyChangeListener{
ArrayList <Message> list = session.getNewMessages(); ArrayList <Message> list = session.getNewMessages();
for (Message msg : list) { for (Message msg : list) {
if (msg.getType().equals("command") && msg.getBody().equals("stopSession")) { if (msg.getType().equals("command") && msg.getBody().equals("stopSession")) {
historicField.setText(historicField.getText() + GestionnaireNom.instance().nomFromId(session.getIdDestination()) + " s'est déconnecté(e).\n"); historicField.setText(historicField.getText() + GestionnaireNom.instance().nomFromId(session.getIdDestination()) + " s'est déconnecté(e)."+System.lineSeparator());
this.finDeSession(); this.finDeSession();
} }
else else
{ {
System.out.print(msg); System.out.print(msg);
String message = GestionnaireNom.instance().nomFromId(msg.getSender()) + ": " + msg.getBody(); String message = GestionnaireNom.instance().nomFromId(msg.getSender()) + ": " + msg.getBody();
historicField.setText(historicField.getText() + message + "\n"); historicField.setText(historicField.getText() + message + System.lineSeparator());
} }
} }
@ -83,8 +83,8 @@ public class DiscussionUI extends JFrame implements PropertyChangeListener{
message.setSender(this.session.getIdSource()); message.setSender(this.session.getIdSource());
message.setRecipient(this.session.getIdDestination()); message.setRecipient(this.session.getIdDestination());
textField.setText(""); textField.setText("");
historicField.append(GestionnaireNom.instance().nomFromId(message.getSender()) +": " + message.getBody() + "\n"); historicField.append(GestionnaireNom.instance().nomFromId(message.getSender()) +": " + message.getBody() + System.lineSeparator());
//session.send(GestionnaireNom.instance().nomFromId(session.getIdSource()) + ": " + message+"\n"); //session.send(GestionnaireNom.instance().nomFromId(session.getIdSource()) + ": " + message+System.lineSeparator());
try { try {
session.sendObject(message); session.sendObject(message);
} catch (IOException e) { } catch (IOException e) {