public MarshalledValue(Object obj) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MarshalledValueOutputStream mvos = new MarshalledValueOutputStream(baos); mvos.writeObject(obj); mvos.flush(); serializedForm = baos.toByteArray(); mvos.close(); // Use the java.rmi.MarshalledObject hash code calculation int hash = 0; for (int i = 0; i < serializedForm.length; i++) { hash = 31 * hash + serializedForm[i]; } hashCode = hash; }
private byte[] externalizeSession(ClusteredSession session) { try { // Write the contents of session to a byte array and store that ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Use MarshalledValueOutputStream instead of superclass ObjectOutputStream // or else there are problems finding classes with scoped loaders MarshalledValueOutputStream oos = new MarshalledValueOutputStream(baos); session.writeExternal(oos); oos.close(); // flushes bytes to baos byte[] bytes = baos.toByteArray(); if (log_.isDebugEnabled()) { log_.debug("marshalled object to size " + bytes.length + " bytes"); } return bytes; } catch (Exception e) { log_.error("externalizeSession(): exception occurred externalizing session " + session, e); return null; } }
MarshalledValueOutputStream oos = new MarshalledValueOutputStream(baos); session.writeExternal(oos); oos.close(); // flushes bytes to baos
MarshalledValueOutputStream oos = new MarshalledValueOutputStream(baos); session.writeExternal(oos); oos.close(); // flushes bytes to baos