/** * Encode the given AEL Message object into a String. * * @param object the Message object being encoded. * @return the encoded object as a string. */ @Override public String encode( Message object ) throws EncodeException { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream( baos ); oos.writeObject( object ); oos.close(); return EncodeUtil.encodeBase64Zipped( baos.toByteArray() ); } catch ( Exception e ) { throw new RuntimeException( "Unexpected error trying to encode object.", e ); } }
/** * Decode the given String into an AEL Message object. * * @param string string to be decoded. * @return the decoded message as an Message object. */ @Override public Message decode( String string ) throws DecodeException { try { byte[] data = EncodeUtil.decodeBase64Zipped( string ); InputStream is = new ByteArrayInputStream( data ); ObjectInputStream ois = new ObjectInputStream( is ); Object o = ois.readObject(); ois.close(); return (Message) o; } catch ( Exception e ) { throw new RuntimeException( "Unexpected error trying to decode object.", e ); } }