-// /** Writes the object and CLOSES the stream. Uses the persistence delegate registered in this class.
-// * @param os The stream to write to. Will be closed.
-// * @param o The object to be serialized.
-// * @param listener The listener to receive the exceptions if there are any. If <code>null</code> not used.
-// */
-// static void writeXMLObject(OutputStream os, Object o, ExceptionListener listener)
-// {
-// ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-// Thread.currentThread().setContextClassLoader(LayoutUtil.class.getClassLoader());
-//
-// XMLEncoder encoder = new XMLEncoder(os);
-//
-// if (listener != null)
-// encoder.setExceptionListener(listener);
-//
-// encoder.writeObject(o);
-// encoder.close(); // Must be closed to write.
-//
-// Thread.currentThread().setContextClassLoader(oldClassLoader);
-// }
-//
-// private static ByteArrayOutputStream writeOutputStream = null;
-// /** Writes an object to XML.
-// * @param out The object out to write to. Will not be closed.
-// * @param o The object to write.
-// */
-// public static synchronized void writeAsXML(ObjectOutput out, Object o) throws IOException
-// {
-// if (writeOutputStream == null)
-// writeOutputStream = new ByteArrayOutputStream(16384);
-//
-// writeOutputStream.reset();
-//
-// writeXMLObject(writeOutputStream, o, new ExceptionListener() {
-// @Override
-// public void exceptionThrown(Exception e) {
-// e.printStackTrace();
-// }});
-//
-// byte[] buf = writeOutputStream.toByteArray();
-//
-// out.writeInt(buf.length);
-// out.write(buf);
-// }
-//
-// private static byte[] readBuf = null;
-// /** Reads an object from <code>in</code> using the
-// * @param in The object input to read from.
-// * @return The object. Never <code>null</code>.
-// * @throws IOException If there was a problem saving as XML
-// */
-// public static synchronized Object readAsXML(ObjectInput in) throws IOException
-// {
-// if (readBuf == null)
-// readBuf = new byte[16384];
-//
-// Thread cThread = Thread.currentThread();
-// ClassLoader oldCL = null;
-//
-// try {
-// oldCL = cThread.getContextClassLoader();
-// cThread.setContextClassLoader(LayoutUtil.class.getClassLoader());
-// } catch(SecurityException ignored) {
-// }
-//
-// Object o = null;
-// try {
-// int length = in.readInt();
-// if (length > readBuf.length)
-// readBuf = new byte[length];
-//
-// in.readFully(readBuf, 0, length);
-//
-// o = new XMLDecoder(new ByteArrayInputStream(readBuf, 0, length)).readObject();
-//
-// } catch(EOFException ignored) {
-// }
-//
-// if (oldCL != null)
-// cThread.setContextClassLoader(oldCL);
-//
-// return o;
-// }
+ /** Writes the object and CLOSES the stream. Uses the persistence delegate registered in this class.
+ * @param os The stream to write to. Will be closed.
+ * @param o The object to be serialized.
+ * @param listener The listener to receive the exceptions if there are any. If <code>null</code> not used.
+ */
+ static void writeXMLObject(OutputStream os, Object o, ExceptionListener listener)
+ {
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(LayoutUtil.class.getClassLoader());
+
+ XMLEncoder encoder = new XMLEncoder(os);
+
+ if (listener != null)
+ encoder.setExceptionListener(listener);
+
+ encoder.writeObject(o);
+ encoder.close(); // Must be closed to write.
+
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+
+ private static ByteArrayOutputStream writeOutputStream = null;
+ /** Writes an object to XML.
+ * @param out The object out to write to. Will not be closed.
+ * @param o The object to write.
+ */
+ public static synchronized void writeAsXML(ObjectOutput out, Object o) throws IOException
+ {
+ if (writeOutputStream == null)
+ writeOutputStream = new ByteArrayOutputStream(16384);
+
+ writeOutputStream.reset();
+
+ writeXMLObject(writeOutputStream, o, new ExceptionListener() {
+ @Override
+ public void exceptionThrown(Exception e) {
+ e.printStackTrace();
+ }});
+
+ byte[] buf = writeOutputStream.toByteArray();
+
+ out.writeInt(buf.length);
+ out.write(buf);
+ }
+
+ private static byte[] readBuf = null;
+ /** Reads an object from <code>in</code> using the
+ * @param in The object input to read from.
+ * @return The object. Never <code>null</code>.
+ * @throws IOException If there was a problem saving as XML
+ */
+ public static synchronized Object readAsXML(ObjectInput in) throws IOException
+ {
+ if (readBuf == null)
+ readBuf = new byte[16384];
+
+ Thread cThread = Thread.currentThread();
+ ClassLoader oldCL = null;
+
+ try {
+ oldCL = cThread.getContextClassLoader();
+ cThread.setContextClassLoader(LayoutUtil.class.getClassLoader());
+ } catch(SecurityException ignored) {
+ }
+
+ Object o = null;
+ try {
+ int length = in.readInt();
+ if (length > readBuf.length)
+ readBuf = new byte[length];
+
+ in.readFully(readBuf, 0, length);
+
+ o = new XMLDecoder(new ByteArrayInputStream(readBuf, 0, length)).readObject();
+
+ } catch(EOFException ignored) {
+ }
+
+ if (oldCL != null)
+ cThread.setContextClassLoader(oldCL);
+
+ return o;
+ }