@Override public synchronized byte[] toByteArray() throws IOException { if (serializedForm == null) { serializedForm = serialize(); } raw = null; return serializedForm; }
/** * The object implements the writeExternal method to save its contents * by calling the methods of DataOutput for its primitive values or * calling the writeObject method of ObjectOutput for objects, strings, * and arrays. * * @serialData Overriding methods should use this tag to describe * the data layout of this Externalizable object. * List the sequence of element types and, if possible, * relate the element to a public/protected field and/or * method of this Externalizable class. * * @param out the stream to write the object to * * @throws IOException Includes any I/O exceptions that may occur */ @Override public synchronized void writeExternal(ObjectOutput out) throws IOException { byte[] bytes = serialize(); int length = bytes != null ? bytes.length : 0; out.writeInt(length); if( length > 0 ) { out.write(bytes); } out.writeInt(hashCode); }