comparison src/org/dancres/blitz/remote/transport/MarshallUtil.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.remote.transport;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.IOException;
6 import java.io.Serializable;
7 import java.rmi.RemoteException;
8
9 import org.dancres.io.AnnotatingObjectInputStream;
10 import org.dancres.io.AnnotatingObjectOutputStream;
11 import org.apache.mina.common.ByteBuffer;
12
13 /**
14 */
15 public class MarshallUtil {
16 public static Message marshall(Serializable aMessage,
17 int aConversationId) throws RemoteException {
18 try {
19 ByteArrayOutputStream myBAOS =
20 new ByteArrayOutputStream();
21
22 AnnotatingObjectOutputStream myOOS =
23 new AnnotatingObjectOutputStream(myBAOS, myBAOS);
24
25 myOOS.writeObject(aMessage);
26 myOOS.close();
27
28 return new Message(aConversationId, myBAOS.toByteArray());
29 } catch (IOException anIOE) {
30 throw new RemoteException("Failed to marhsall", anIOE);
31 }
32 }
33
34 public static Object unmarshall(Message aMessage) throws RemoteException {
35 ByteArrayInputStream myBAIS =
36 new ByteArrayInputStream(aMessage.getPayload());
37
38 AnnotatingObjectInputStream myOIS = null;
39
40 try {
41 myOIS =
42 new AnnotatingObjectInputStream(null, myBAIS, myBAIS, false);
43
44 Object myResult = myOIS.readObject();
45
46 myOIS.close();
47
48 return myResult;
49
50 } catch (Exception anE) {
51 if (myOIS != null) {
52 try {
53 myOIS.close();
54 } catch (IOException anIOE) {
55 }
56 }
57
58 throw new RemoteException("Failed to unmarshall", anE);
59 }
60 }
61 }