Search in sources :

Example 1 with SimpleDataInput

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

the class SimpleMarshalledValue method get.

/**
     * {@inheritDoc}
     * @see org.wildfly.clustering.marshalling.spi.MarshalledValue#get(java.lang.Object)
     */
@SuppressWarnings("unchecked")
@Override
public synchronized T get(MarshallingContext context) throws IOException, ClassNotFoundException {
    if (this.object == null) {
        this.context = context;
        if (this.bytes != null) {
            ByteArrayInputStream input = new ByteArrayInputStream(this.bytes);
            ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader());
            try (SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input))) {
                int version = IndexExternalizer.VARIABLE.readData(data);
                try (Unmarshaller unmarshaller = context.createUnmarshaller(version)) {
                    unmarshaller.start(data);
                    this.object = (T) unmarshaller.readObject();
                    unmarshaller.finish();
                    // Free up memory
                    this.bytes = null;
                }
            } finally {
                setThreadContextClassLoader(loader);
            }
        }
    }
    return this.object;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Unmarshaller(org.jboss.marshalling.Unmarshaller) SimpleDataInput(org.jboss.marshalling.SimpleDataInput)

Example 2 with SimpleDataInput

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

the class JBossByteBufferMarshaller method readFrom.

@Override
public Object readFrom(InputStream input) throws IOException {
    try (SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input))) {
        int version = IndexSerializer.UNSIGNED_BYTE.readInt(data);
        ClassLoader loader = setThreadContextClassLoader(this.loader.get());
        try (Unmarshaller unmarshaller = this.factory.createUnmarshaller(this.repository.getMarshallingConfiguration(version))) {
            unmarshaller.start(data);
            Object result = unmarshaller.readObject();
            unmarshaller.finish();
            return result;
        } catch (ClassNotFoundException e) {
            InvalidClassException exception = new InvalidClassException(e.getMessage());
            exception.initCause(e);
            throw exception;
        } finally {
            setThreadContextClassLoader(loader);
        }
    }
}
Also used : InvalidClassException(java.io.InvalidClassException) Unmarshaller(org.jboss.marshalling.Unmarshaller) SimpleDataInput(org.jboss.marshalling.SimpleDataInput)

Aggregations

SimpleDataInput (org.jboss.marshalling.SimpleDataInput)2 Unmarshaller (org.jboss.marshalling.Unmarshaller)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InvalidClassException (java.io.InvalidClassException)1