Project

General

Profile

Statistics
| Revision:

root / src / messages / RestoreFile.java

History | View | Annotate | Download (1.51 KB)

1 1 up20150524
package messages;
2
3
import chord.ChordManager;
4
import chord.ConnectionInfo;
5
import files.FileHandler;
6
import peer.Peer;
7
8
import java.io.IOException;
9
import java.math.BigInteger;
10
import java.net.UnknownHostException;
11
import java.util.concurrent.ExecutionException;
12
13
public class RestoreFile extends Message {
14
    private ConnectionInfo ci;
15
    private BigInteger hashFile;
16
    private String filename;
17
    private byte[] body;
18
    private String ipAddress;
19
    private int port;
20
21
    public RestoreFile(ConnectionInfo ci, BigInteger hashFile, String filename, byte[] body, String ipAddress, int port) {
22
        this.ci = ci;
23
        this.filename = filename;
24
        this.hashFile = hashFile;
25
        this.body = body;
26
        this.ipAddress = ipAddress;
27
        this.port = port;
28
    }
29
30
    @Override
31
    public void handleMessage() throws UnknownHostException {
32
33
        try {
34
            FileHandler.writeFile("./peerDisk/peer" + Peer.getPeerAccessPoint() + "-" + ChordManager.peerHash + "/restored/" + filename, body);
35
        } catch (IOException e) {
36
            e.printStackTrace();
37
        } catch (ExecutionException e) {
38
            e.printStackTrace();
39
        } catch (InterruptedException e) {
40
            e.printStackTrace();
41
        }
42
    }
43
44
    @Override
45
    public String toString() {
46
        return "RESTORE WITH FILE " + this.ci + " " + this.hashFile + " " + this.filename;
47
    }
48
49
    @Override
50
    public String getIpAddress() {
51
        return ipAddress;
52
    }
53
54
    @Override
55
    public int getPort() {
56
        return port;
57
    }
58
}