use of org.gradle.internal.io.ClassLoaderObjectInputStream in project gradle by gradle.
the class SerializationFixture method serializationRoundtrip.
public static <T> T serializationRoundtrip(T obj) {
try {
StreamByteBuffer buffer = new StreamByteBuffer();
ObjectOutputStream out = new ObjectOutputStream(buffer.getOutputStream());
out.writeObject(obj);
out.close();
ClassLoaderObjectInputStream input = new ClassLoaderObjectInputStream(buffer.getInputStream(), obj.getClass().getClassLoader());
return (T) input.readObject();
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of org.gradle.internal.io.ClassLoaderObjectInputStream in project gradle by gradle.
the class InProcessWorkerFactory method transferWorkerIntoWorkerClassloader.
private <T extends WorkSpec> Callable<?> transferWorkerIntoWorkerClassloader(WorkerAction<T> action, T spec, ClassLoader workerClassLoader) throws IOException, ClassNotFoundException {
byte[] serializedWorker = GUtil.serialize(new WorkerCallable<T>(action, spec));
ObjectInputStream ois = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), workerClassLoader);
return (Callable<?>) ois.readObject();
}
use of org.gradle.internal.io.ClassLoaderObjectInputStream in project gradle by gradle.
the class SerializedValueSnapshot method snapshot.
@Override
public ValueSnapshot snapshot(Object value, ValueSnapshotter snapshotter) {
ValueSnapshot snapshot = snapshotter.snapshot(value);
if (snapshot instanceof SerializedValueSnapshot) {
SerializedValueSnapshot newSnapshot = (SerializedValueSnapshot) snapshot;
if (!Objects.equal(implementationHash, newSnapshot.implementationHash)) {
// Different implementation - assume value has changed
return newSnapshot;
}
if (Arrays.equals(serializedValue, newSnapshot.serializedValue)) {
// Same serialized content - value has not changed
return this;
}
// Deserialize the old value and use the equals() implementation. This will be removed at some point
Object oldValue;
try {
oldValue = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedValue), value.getClass().getClassLoader()).readObject();
} catch (Exception e) {
throw new UncheckedIOException(e);
}
if (oldValue.equals(value)) {
// Same value
return this;
}
}
return snapshot;
}
use of org.gradle.internal.io.ClassLoaderObjectInputStream in project gradle by gradle.
the class SystemApplicationClassLoaderWorker method deserializeWorker.
private Action<WorkerProcessContext> deserializeWorker(byte[] serializedWorker) {
Action<WorkerProcessContext> action;
try {
ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader());
@SuppressWarnings("unchecked") Action<WorkerProcessContext> deserializedAction = (Action<WorkerProcessContext>) instr.readObject();
action = deserializedAction;
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
return action;
}
use of org.gradle.internal.io.ClassLoaderObjectInputStream in project gradle by gradle.
the class IsolatedClassloaderWorkerFactory method transferWorkerIntoWorkerClassloader.
private Callable<?> transferWorkerIntoWorkerClassloader(ActionExecutionSpec spec, ClassLoader workerClassLoader) throws IOException, ClassNotFoundException {
byte[] serializedWorker = GUtil.serialize(new WorkerCallable(spec));
ObjectInputStream ois = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), workerClassLoader);
return (Callable<?>) ois.readObject();
}
Aggregations