Search in sources :

Example 1 with ArtifactClassLoaderObjectOutputStream

use of org.mule.runtime.module.artifact.api.serializer.ArtifactClassLoaderObjectOutputStream in project mule by mulesoft.

the class CustomJavaSerializationProtocol method doSerialize.

/**
 * {@inheritDoc}
 */
@Override
protected byte[] doSerialize(Object object) throws Exception {
    // TODO: MULE-11939
    if (object instanceof CursorStreamProvider) {
        try (CursorStream cursor = ((CursorStreamProvider) object).openCursor()) {
            object = toByteArray(cursor);
        }
    }
    validateForSerialization(object);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
    try (ObjectOutputStream out = new ArtifactClassLoaderObjectOutputStream(classLoaderRepository, outputStream)) {
        out.writeObject(object);
    } catch (IOException ex) {
        throw new SerializationException("Cannot serialize object", ex);
    }
    return outputStream.toByteArray();
}
Also used : CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) SerializationException(org.mule.runtime.api.serialization.SerializationException) ArtifactClassLoaderObjectOutputStream(org.mule.runtime.module.artifact.api.serializer.ArtifactClassLoaderObjectOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ArtifactClassLoaderObjectOutputStream(org.mule.runtime.module.artifact.api.serializer.ArtifactClassLoaderObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 SerializationException (org.mule.runtime.api.serialization.SerializationException)1 CursorStream (org.mule.runtime.api.streaming.bytes.CursorStream)1 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)1 ArtifactClassLoaderObjectOutputStream (org.mule.runtime.module.artifact.api.serializer.ArtifactClassLoaderObjectOutputStream)1