package summer.serializable;

import java.io.*;
import java.util.Date;

/**
 * @ClassName: Vulnerability
 * @Description: TODO
 * @Author: summer
 * @Date: 2020/4/22 17:27
 * @Version: v1.0.0
 **/
public class VulnerabilityDemo {
    private static Object VulnerabilityClass;

    public static void main(String[] args) {
       // 调用序列化方法
        Serilizable();
        // 反序列化方法
        UnSerializable();

    }


    /**
     * @Author:         summer
     * @CreateDate:     2020/4/22 17:50
     * @UpdateUser:     summer
     * @UpdateDate:     2020/4/22 17:50
     * @UpdateRemark:   修改内容
     * @Version:        v1.0.0
     * @Description:    序列化方法
     */
    public static void Serilizable(){
        VulnerabilityClass clazz = new VulnerabilityClass();
        clazz.setDate(new Date());
        clazz.setId(1314520);
        clazz.setPassword("summer6666");
        clazz.setUsername("summer");

        // 写文件
        File file = new File("tempFile3");
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
            oos.writeObject(clazz);
            System.out.println("serilizable: " + clazz);
            oos.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static Object UnSerializable(){

        File file = new File("tempFile3");
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
            VulnerabilityClass clazz = (VulnerabilityClass) ois.readObject();
            System.out.println("unserializable: " + clazz);
            ois.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return VulnerabilityClass;
    }


}
