From 72ce99fd6ffa8bd5cea693517a3597e7200bd7f5 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 21 Jan 2020 10:37:21 +0100 Subject: [PATCH] Fix NOT FOUND --- src/clientP2P/ClientManagementUDP.java | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/clientP2P/ClientManagementUDP.java b/src/clientP2P/ClientManagementUDP.java index 36cb5e5..68796ec 100644 --- a/src/clientP2P/ClientManagementUDP.java +++ b/src/clientP2P/ClientManagementUDP.java @@ -78,18 +78,22 @@ public class ClientManagementUDP implements Runnable { try { String r[] = response.split("\n", 3); checkProtocolID(r[0]); - String r2[] = r[1].split(" "); - if (r2[0] != "LOAD") { + String r2[] = r[1].split("\n"); + switch (r2[0]) { + case "LOAD": + int size = Integer.parseInt(r2[1]); + if (r[2].length() != size) { + throw new TransmissionError(); + } + FileWriter fileWriter = new FileWriter(baseDirectory + filename); + fileWriter.write(r[2]); + fileWriter.close(); + break; + case "NOT FOUND": + throw new NotFound(); + default: throw new ProtocolError(); } - int size = Integer.parseInt(r2[1]); - if (r[2].length() != size) { - throw new TransmissionError(); - } - FileWriter fileWriter = new FileWriter(baseDirectory + filename); - fileWriter.write(r[2]); - fileWriter.close(); - } catch (java.lang.ArrayIndexOutOfBoundsException e) { throw new ProtocolError(); } catch (NumberFormatException e) { @@ -113,7 +117,7 @@ public class ClientManagementUDP implements Runnable { try { String r[] = response.split("\n"); checkProtocolID(r[0]); - return response.split(protocolID + "\nLIST\n")[1]; + return response.split(protocolID + "\nLIST\n")[1].split("\n\n")[0]; } catch (java.lang.ArrayIndexOutOfBoundsException e) { throw new ProtocolError(); }