Add send method + update documentation
This commit is contained in:
parent
e7b4d7a5c3
commit
acaa363153
@ -1 +1 @@
|
||||
<mxfile host="www.draw.io" modified="2020-01-12T21:02:58.379Z" agent="Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" etag="OeM4nER5jpnihrTPHdYv" version="12.5.1" type="device"><diagram id="MxademQTiYvtQCVb_gz8" name="Page-1">7VzZduI4EP0azul+IAcvbI9hSXfPkAwn6XVe5ghbgDrCYmQRoL++JVvehW2CTc/ip1hlWVi6Vbeuy3JaxnhzeEfBdn1PbIhbesc+tIxJS9c10+zzP8Jy9C0DQ/cNK4ps2SkyPKEfUBo70rpDNnQTHRkhmKFt0mgRx4EWS9gApWSf7LYkOPmrW7CCGcOTBXDW+gXZbC1nofcj+3uIVuvgl7Xe0D+zAUFnORN3DWyyj5mMacsYU0KYf7Q5jCEWixesi3/d3Ymz4Y1R6LAyF/zh2t9A+7fN7cNqD8a7D+DL4KkdzMNlx2DG0OYLIJuEsjVZEQfgaWQdUbJzbCiG7fBW1GdGyJYbNW78Dhk7SjTBjhFuWrMNlmf5HdPjV3H9jdkPDd/kgF5jcki0jvHWHFK0gQzS0GjfCqh50yEO9C13CGN5PrtScvFcsqOWnPaR4NWU2dbjHv/+cXpcPL9Hs7bEkgG6giynn2b4HcXaxX5BAvEOEn679Mg7UIgBQy9J5wLSR1dhvwhGfiCRVKOad9svAO/kL40xEpNPY+3u0QYDb8mWxGEB7AISgNHK4ccWv06s9OgFUoZ4YNzKE0yAPbLWCNszcCQ7sT4uA9Zz0BqtCUU/+LAgwJ2fpkx6hd5L9HgSV0q8KHR5n3mAl5Yy3YNDouMMuEwaLIIx2LpoEU5jw6FDzogwRjZF7iBmCA+5+Mmzg6EMaslqfdncRxSh9aRtHaOHwFY54pqWgTwDNkYe0C6j5DkkM7FGSx4qY4IJjQIoQB/DJVNgv0G27VGBuwUWclYfvcBva5Fl5l04MSLLo1wGw2MQBhjwURKQYLCAeE5cxBAR41O/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3McqqyTD+sgFSViGc5NZJX26y2CnnBjoRZp2GFkr5xOuYufo9jViCqlLdXYlfG/0RTVQ9u2R2UddG9qkI7avbX1Qq5XhLyCvbXKW+vRFGtiefiRK6lqjCmYj9FTQ9HSlh/0ScNZb5BSNVSC1+i51FV/B16juy+tF7LZwWOsQ7SvU6Wc430/rhu6rOU8/rzA/8OXlumVS5hsMHyyj4S7NFoxXZohPs1CvZoJD+TuSnapnlFf1R8JJNTtLjCNzF5dxkj+1TZoXmsqyQbdNPZYHDF3XXqYG++jblExA1zRdwVN9epwc0+tf/Dd9cVfeJYnpnjjHsOdDXsmevpyag3gue5c1/hpgfKvCKp7gWu2p96/3H1qJWWj5em61fJx/Tm7J6ZLx/T/YN2vfIxWy143DmOR9oZHbEGW3G4peQFcScRr1wQhfYHoR2WQGAV94Qgm8xSrL+QabqSFD1IrbHitbmuehA//6U5b0ZfuPvLH/2fAGP6Ew==</diagram></mxfile>
|
||||
<mxfile host="www.draw.io" modified="2020-01-12T21:18:15.190Z" agent="Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" etag="AragDVgr5JVvbnQoNFHI" version="12.5.1" type="device"><diagram id="MxademQTiYvtQCVb_gz8" name="Page-1">7Vxbc9o4FP41mWkfksE3Lo+BkLa7JMskve7LjmIL0EZYrCwC9NevZMs3WRgTbNruug8d61gSkr5z+XQs5cIaLbfvKFgt7ogH8YXZ8bYX1s2FafZMi/8vBLtIYBvdSDCnyItERip4RN+hFHakdI08GOQqMkIwQ6u80CW+D12WkwFKySZfbUZw/ldXYA4LgkcX4KL0C/LYIpL2zV4qfw/RfBH/stEdRG+WIK4sZxIsgEc2GZE1vrBGlBAWPS23I4jF2sXrErW73fM2GRiFPqvS4I/A+wYuf1te3883YLT+AL70Hy/jeQRsF88YenwBZJFQtiBz4gM8TqVDSta+B0W3HV5K60wIWXGhwYV/Q8Z2Ek2wZoSLFmyJ5Vs+Yrr7Ktpf2b1E8E12GBZutrnSLluaQo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
@ -9,3 +9,4 @@ All messages begins with `P2P-JAVA-PROJECT VERSION 1.0\n` (this version of the p
|
||||
- The response to `LIST` request is in the format `LIST\n<FILENAME 1>\n<FILENAME 2>\n[…]<LAST FILENAME>\n\n`
|
||||
- The response to `DOWNLOAD` request is `LOAD <FILESIZE (BYTES)>\n<CONTENT OF FILE>` or `NOT FOUND\n` if the file doesn't exists.
|
||||
- The server send a `PROTOCOL ERROR\n` message if it doesn't understands what the client sent.
|
||||
- The server send a `INTERNAL ERROR\n` message if it encounters an internal error.
|
||||
|
2
src/exception/InternalError.java
Normal file
2
src/exception/InternalError.java
Normal file
@ -0,0 +1,2 @@
|
||||
package exception;
|
||||
public class InternalError extends Exception {}
|
@ -6,6 +6,7 @@ import java.net.Datagram.Packet;
|
||||
import java.net.Datagram.Socket;
|
||||
import exception.ProtocolError;
|
||||
import exception.NotFound;
|
||||
import exception.InternalError;
|
||||
|
||||
|
||||
/** Implementation of P2P-JAVA-PROJECT VERSION 1.0 protocol for UDP.
|
||||
@ -85,6 +86,8 @@ public class ServerManagementUDP implements Runnable {
|
||||
} catch (ProtocolError e) {
|
||||
// wrong version or wrong implementation
|
||||
res += sendProtocolError();
|
||||
} catch (InternalError e) {
|
||||
res += sendInternalError();
|
||||
} catch (NotFound e) {
|
||||
res += sendNotFound();
|
||||
}
|
||||
@ -118,9 +121,20 @@ public class ServerManagementUDP implements Runnable {
|
||||
* @param filename name of the file to be send
|
||||
* @return data to be send
|
||||
* @throws NotFound
|
||||
* @throws InternalError
|
||||
*/
|
||||
private String upload(String filename) throws NotFound {
|
||||
// TODO
|
||||
private String upload(String filename) throws NotFound, InternalError {
|
||||
File file = new File(filename);
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw NotFound;
|
||||
}
|
||||
String res = "LOAD " + file.length(); + "\n"
|
||||
try {
|
||||
res += new String(Files.readAllBytes(Paths.get(filename)));
|
||||
} catch (IOException e) {
|
||||
throw InternalError;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/** Prepare the data to be send if file list is requested
|
||||
@ -147,5 +161,12 @@ public class ServerManagementUDP implements Runnable {
|
||||
private String sendNotFound() {
|
||||
return "NOT FOUND\n"
|
||||
}
|
||||
|
||||
/** Prepare data to be send if internal error encounterred
|
||||
* @return data to be send
|
||||
*/
|
||||
private String sendInternalError() {
|
||||
return "INTERNAL ERROR\n"
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user