-
Notifications
You must be signed in to change notification settings - Fork 0
/
SyncPacket.java
48 lines (42 loc) · 1.13 KB
/
SyncPacket.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.*;
public class SyncPacket extends Packet {
private String fileName;
private long fileSize;
public SyncPacket (boolean ack, boolean payL, boolean sync, String fn, long fs) {
super(ack, payL, sync);
this.fileName = fn;
this.fileSize = fs;
}
public String getFileName () {
return fileName;
}
public long getFileSize () {
return fileSize;
}
public void SerializePacket (String fileName) {
try{
FileOutputStream fileOut = new FileOutputStream(fileName);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved as " + fileName);
}catch(IOException i){
i.printStackTrace();
}
}
public void DeSerializePacket (String fileName){
try{
FileInputStream fileIn = new FileInputStream(fileName);
ObjectInputStream in = new ObjectInputStream(fileIn);
this = (SyncPacket) in.readObject();
in.close();
fileIn.close();
}catch(IOException i){
i.printStackTrace();
}catch(ClassNotFoundException c){
System.out.println("Student class not found");
c.printStackTrace();
}
}
}