-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayloadPacket.java
56 lines (49 loc) · 1.25 KB
/
PayloadPacket.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
49
50
51
52
53
54
55
56
import java.util.Arrays;
import java.io.*;
public class PayloadPacket extends Packet {
private int id;
private int length;
private byte[] data;
public PayloadPacket (boolean ack, boolean payL, boolean sync, int i, int l, byte[] d) {
super(ack, payL, sync);
this.id = i;
this.length = l;
this.data = new byte[l];
this.data = Arrays.copyOf(d,l);
}
public int getId () {
return id;
}
public int getLength () {
return length;
}
public byte[] getData () {
return data;
}
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 = (PayloadPacket) in.readObject();
in.close();
fileIn.close();
}catch(IOException i){
i.printStackTrace();
}catch(ClassNotFoundException c){
System.out.println("Student class not found");
c.printStackTrace();
}
}
}