|
|
|
@ -76,27 +76,31 @@ public class ClientManagementUDP implements Runnable {
|
|
|
|
|
*/
|
|
|
|
|
private void download(String response, String filename) throws TransmissionError, NotFound, ProtocolError, InternalError, IOException {
|
|
|
|
|
try {
|
|
|
|
|
String r[] = response.split("\n", 3);
|
|
|
|
|
String r[] = response.split("\n");
|
|
|
|
|
checkProtocolID(r[0]);
|
|
|
|
|
String r2[] = r[1].split("\n");
|
|
|
|
|
switch (r2[0]) {
|
|
|
|
|
switch (r[1]) {
|
|
|
|
|
case "LOAD":
|
|
|
|
|
int size = Integer.parseInt(r2[1]);
|
|
|
|
|
if (r[2].length() != size) {
|
|
|
|
|
int size = Integer.parseInt(r[2]);
|
|
|
|
|
if (r[3].length() != size + 1) {
|
|
|
|
|
throw new TransmissionError();
|
|
|
|
|
}
|
|
|
|
|
FileWriter fileWriter = new FileWriter(baseDirectory + filename);
|
|
|
|
|
fileWriter.write(r[2]);
|
|
|
|
|
fileWriter.write(r[3]);
|
|
|
|
|
fileWriter.close();
|
|
|
|
|
break;
|
|
|
|
|
case "NOT FOUND":
|
|
|
|
|
throw new NotFound();
|
|
|
|
|
case "INTERNAL ERROR":
|
|
|
|
|
throw new InternalError();
|
|
|
|
|
default:
|
|
|
|
|
System.out.println("Error: Unknow format `" + r[1] + "`");
|
|
|
|
|
throw new ProtocolError();
|
|
|
|
|
}
|
|
|
|
|
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
|
|
|
|
|
System.out.println("Error: IndexOutOfBonds");
|
|
|
|
|
throw new ProtocolError();
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println("Error: NumberFormat");
|
|
|
|
|
throw new ProtocolError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|