-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlip3.java
More file actions
55 lines (49 loc) · 1.49 KB
/
Blip3.java
File metadata and controls
55 lines (49 loc) · 1.49 KB
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
package btp.oneP;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
public class Blip3 implements Externalizable {
private int i;
private String s;
public Blip3(){
System.out.println("Blip3 Constructor");
}
public Blip3(String x,int a){
System.out.println("Blip3(String x,int a)");
s = x;
i = a;
}
public String toString(){
return s + i;
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
System.out.println("Blip3.writeExternal");
out.writeObject(s);
out.writeInt(i);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// TODO Auto-generated method stub
System.out.println("Blip3.readExternal");
s = (String)in.readObject();
i = in.readInt();
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
// TODO Auto-generated method stub
Blip3 b3 = new Blip3("A string",47);
System.out.println(b3);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(bout);
o.writeObject(b3);
o.close();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
b3 = (Blip3) in.readObject();
System.out.println(b3);
}
}