content: package com.vua.upms.client.util;
  
  import org.apache.commons.lang.StringUtils;
  import org.apache.shiro.codec.Base64;
  import org.apache.shiro.session.Session;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  
  /**
   * Created by liunian on 6/7/17.
   */
  public class SerializableUtil {
  
      public static String serialize(Session session) {
          if (null == session) {
              return null;
          }
          try {
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(bos);
              oos.writeObject(session);
              return Base64.encodeToString(bos.toByteArray());
          } catch (Exception e) {
              throw new RuntimeException("serialize session error", e);
          }
      }
  
      public static Session deserialize(String sessionString) {
          if (StringUtils.isBlank(sessionString)) {
              return null;
          }
          try {
              ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(sessionString));
              ObjectInputStream ois = new ObjectInputStream(bis);
              return (Session)ois.readObject();
          } catch (Exception e) {
              throw new RuntimeException("deserialize session error", e);
          }
      }
  }
  