org.infinispan.commons.marshall.SuppliedExternalizer Maven / Gradle / Ivy
The newest version!
package org.infinispan.commons.marshall;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Set;
import java.util.function.Supplier;
import org.infinispan.commons.util.Util;
public class SuppliedExternalizer implements AdvancedExternalizer {
private final Integer id;
private final Class clazz;
private final Supplier supplier;
public SuppliedExternalizer(Integer id, Class clazz, Supplier supplier) {
this.id = id;
this.clazz = clazz;
this.supplier = supplier;
}
@Override
public Set> getTypeClasses() {
return Util.asSet(clazz);
}
@Override
public Integer getId() {
return id;
}
@Override
public void writeObject(ObjectOutput output, T object) throws IOException {
}
@Override
public T readObject(ObjectInput input) throws IOException, ClassNotFoundException {
return supplier.get();
}
}