List of usage examples for org.apache.shiro.io SerializationException SerializationException
public SerializationException(Throwable cause)
From source file:com.github.zhangkaitao.shiro.chapter7.cache.SerializationUtils.java
License:Apache License
/** * <p>Serializes an {@code Object} to the specified stream.</p> * * <p>The stream will be closed once the object is written. * This avoids the need for a finally clause, and maybe also exception * handling, in the application code.</p> * * <p>The stream passed in is not buffered internally within this method. * This is the responsibility of your application if desired.</p> * * @param obj the object to serialize to bytes, may be null * @param outputStream the stream to write to, must not be null * @throws IllegalArgumentException if {@code outputStream} is {@code null} * @throws SerializationException (runtime) if the serialization fails *//*from w w w . ja v a2s .c o m*/ public static void serialize(Serializable obj, OutputStream outputStream) { if (outputStream == null) { throw new IllegalArgumentException("The OutputStream must not be null"); } ObjectOutputStream out = null; try { // stream closed in the finally out = new ObjectOutputStream(outputStream); out.writeObject(obj); } catch (IOException ex) { throw new SerializationException(ex); } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { // NOPMD // ignore close exception } } }
From source file:com.github.zhangkaitao.shiro.chapter7.cache.SerializationUtils.java
License:Apache License
/** * <p>Deserializes an {@code Object} from the specified stream.</p> * * <p>The stream will be closed once the object is written. This * avoids the need for a finally clause, and maybe also exception * handling, in the application code.</p> * * <p>The stream passed in is not buffered internally within this method. * This is the responsibility of your application if desired.</p> * * @param inputStream the serialized object input stream, must not be null * @return the deserialized object/*from w ww .ja v a 2 s . co m*/ * @throws IllegalArgumentException if {@code inputStream} is {@code null} * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("The InputStream must not be null"); } ObjectInputStream in = null; try { // stream closed in the finally in = new ObjectInputStream(inputStream); return in.readObject(); } catch (ClassNotFoundException ex) { throw new SerializationException(ex); } catch (IOException ex) { throw new SerializationException(ex); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) { // NOPMD // ignore close exception } } }