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;
}
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);
}
}
}
Aggregations