把Session转换成Base64编码

把Session对象转换成Base64编码

  @Test
    public void test2() throws IOException, ClassNotFoundException {
        People people=new People();
        people.setAge(100);
        people.setId(13);
        people.setName("ddd");
        people.setSex(Gender.FEMALE);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(people);
        objectOutputStream.close();
        byte[] bytes = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        String toString = Base64.getEncoder().encodeToString(bytes);
        System.out.println(toString);
        byte[] decode = Base64.getDecoder().decode(toString);
        ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(decode);
        ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);
        Object readObject = objectInputStream.readObject();
        System.out.println(readObject);
    }

你可能感兴趣的:(session,Base64)