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