Search in sources :

Example 1 with SimpleDataOutput

use of org.jboss.marshalling.SimpleDataOutput in project wildfly by wildfly.

the class SimpleMarshalledValue method getBytes.

byte[] getBytes() throws IOException {
    byte[] bytes = this.bytes;
    if (bytes != null)
        return bytes;
    if (this.object == null)
        return null;
    int version = this.context.getCurrentVersion();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader());
    try (SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output))) {
        IndexExternalizer.VARIABLE.writeData(data, version);
        try (Marshaller marshaller = this.context.createMarshaller(version)) {
            marshaller.start(data);
            marshaller.writeObject(this.object);
            marshaller.finish();
            return output.toByteArray();
        }
    } finally {
        setThreadContextClassLoader(loader);
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleDataOutput(org.jboss.marshalling.SimpleDataOutput)

Example 2 with SimpleDataOutput

use of org.jboss.marshalling.SimpleDataOutput in project wildfly by wildfly.

the class JBossByteBufferMarshaller method writeTo.

@Override
public void writeTo(OutputStream output, Object value) throws IOException {
    int version = this.repository.getCurrentMarshallingVersion();
    try (SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output))) {
        IndexSerializer.UNSIGNED_BYTE.writeInt(data, version);
        ClassLoader loader = setThreadContextClassLoader(this.loader.get());
        try (Marshaller marshaller = this.factory.createMarshaller(this.getMarshallingConfiguration(version))) {
            marshaller.start(data);
            marshaller.writeObject(value);
            marshaller.finish();
        } finally {
            setThreadContextClassLoader(loader);
        }
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) ByteBufferMarshaller(org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller) SimpleDataOutput(org.jboss.marshalling.SimpleDataOutput)

Aggregations

Marshaller (org.jboss.marshalling.Marshaller)2 SimpleDataOutput (org.jboss.marshalling.SimpleDataOutput)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ByteBufferMarshaller (org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller)1