1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| tampon = new byte[5096];
paquet = new DatagramPacket(tampon, tampon.length,
adresseDistante, portDistant);
try {
socketDownloader.receive(paquet);
} catch (Exception ex) {
System.out.println("Erreur Downloader : " + ex);
}
// On recupere le message recu.
message = new String(tampon, 0, paquet.getLength());
// On traite le message.
if (message.startsWith("req_data " + nameFile)) {
String[] tab = message.split(" ", 5);
int p = Integer.decode(tab[2]);
int length = Integer.decode(tab[3]);
byte[] data = new byte[Math.min(length, lengthMax)];
data = tab[4].getBytes();
String nomFicSortie = repertoireLocal + "/" + nameFile;
String extFicSortie = ".[FS]." + tab[2];
File ficSortie = new File(nomFicSortie + extFicSortie);
FileOutputStream fluxSortie = new FileOutputStream(ficSortie);
fluxSortie.write(data, 0, Math.min(length, lengthMax));
fluxSortie.flush();
fluxSortie.close();
System.out.println("Reception de la partie " + p + " du fichier " + nameFile + " : " + Arrays.toString(data)); |
Partager