- package com.bird.thinking;
-
- import java.io.Externalizable;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- 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;
- }
-
- public void writeExternal(ObjectOutput out){
- System.out.println("Blip3.writeExternal");
- try {
- out.writeObject(s);
- out.writeInt(i);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- public void readExternal(ObjectInput in){
- System.out.println("Blip3.readExternal");
- try {
- s = (String)in.readObject();
- i = in.readInt();
- } catch (ClassNotFoundException e) {
-
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- }
-
- public void read() throws FileNotFoundException, IOException, ClassNotFoundException{
- ObjectInputStream in = new ObjectInputStream(new FileInputStream("d://Blip3.out"));
- System.out.println("Revovering b3");
- Blip3 b3 = (Blip3)in.readObject();
- System.out.println(b3);
- }
-
- public void write() throws Exception{
- Blip3 b3 = new Blip3("A String", 47);
- System.out.println(b3);
- ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("d://Blip3.out"));
- System.out.println("Saving Object");
- o.writeObject(b3);
- o.close();
- }
-
- public static void main(String[] args) throws Exception{
- Blip3 b = new Blip3();
-
- b.read();
- }
- }
|