本文整理汇总了Java中org.objenesis.strategy.StdInstantiatorStrategy类的典型用法代码示例。如果您正苦于以下问题:Java StdInstantiatorStrategy类的具体用法?Java StdInstantiatorStrategy怎么用?Java StdInstantiatorStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StdInstantiatorStrategy类属于org.objenesis.strategy包,在下文中一共展示了StdInstantiatorStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createKryoInstance
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
private Kryo createKryoInstance() {
Kryo kryo = new Kryo();
kryo.register(RakTable.class);
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
kryo.setReferences(false);
kryo.register(Collections.singletonList("").getClass(), new ArraysAsListSerializer());
UnmodifiableCollectionsSerializer.registerSerializers(kryo);
SynchronizedCollectionsSerializer.registerSerializers(kryo);
kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(), new CollectionSerializer());
kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(), new CollectionSerializer());
kryo.register(UUID.class, new UUIDSerializer());
for (Class<?> clazz : mCustomSerializers.keySet()) {
kryo.register(clazz, mCustomSerializers.get(clazz));
}
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}
示例2: create
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
/**
* Creates a Kryo instance.
*
* @return Kryo instance
*/
@Override
public Kryo create() {
log.trace("Creating Kryo instance for {}", this);
Kryo kryo = new Kryo();
kryo.setRegistrationRequired(registrationRequired);
// TODO rethink whether we want to use StdInstantiatorStrategy
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
for (RegistrationBlock block : registeredBlocks) {
int id = block.begin();
if (id == FLOATING_ID) {
id = kryo.getNextRegistrationId();
}
for (Pair<Class<?>, Serializer<?>> entry : block.types()) {
register(kryo, entry.getLeft(), entry.getRight(), id++);
}
}
return kryo;
}
示例3: forSerialization
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
/**
* Returns a new {@link LogicalPlanSerializer}
* @param cluster cluster to used during serialization
*/
public static LogicalPlanSerializer forSerialization(final RelOptCluster cluster) {
final Kryo kryo = new Kryo();
// use objenesis for creating mock objects
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
final CalciteCatalogReader catalog = kryo.newInstance(CalciteCatalogReader.class);
final StoragePluginRegistry registry = kryo.newInstance(StoragePluginRegistryImpl.class);
final RelSerializer serializer = RelSerializer.newBuilder(kryo, cluster, catalog, registry).build();
return new LogicalPlanSerializer() {
@Override
public byte[] serialize(final RelNode plan) {
return serializer.serialize(plan);
}
};
}
示例4: testSerializationRoundTrip
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
@Test
@Ignore
public void testSerializationRoundTrip() throws FileNotFoundException {
// this test to see if can use kryo to serialize RTree instance
List<Entry<Object, Point>> entries = GreekEarthquakes.entriesList();
int maxChildren = 8;
RTree<Object, Point> tree = RTree.maxChildren(maxChildren).<Object, Point> create()
.add(entries);
File file = new File("target/greek-serialized.kryo");
file.delete();
Kryo kryo = new Kryo();
Output output = new Output(new FileOutputStream(file));
kryo.writeObject(output, tree);
output.close();
Input input = new Input(new FileInputStream(file));
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
@SuppressWarnings("unchecked")
RTree<Object, Point> tree2 = kryo.readObject(input, RTree.class);
assertNotNull(tree2);
}
示例5: createKryo
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
public Kryo createKryo() {
Kryo kryo = new Kryo(new DefaultClassResolver(), new MapReferenceResolver() {
@Override
public boolean useReferences(Class type) {
// avoid calling System.identityHashCode
if (type == String.class || type == Date.class) {
return false;
}
return super.useReferences(type);
}
});
registerClasses(kryo);
kryo.setAutoReset(true);
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}
示例6: createKryoInstance
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
private Kryo createKryoInstance() {
Kryo kryo = new Kryo();
kryo.register(IronTable.class);
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
kryo.setReferences(false);
// Serialize Arrays$ArrayList
//noinspection ArraysAsListWithZeroOrOneArgument
kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
UnmodifiableCollectionsSerializer.registerSerializers(kryo);
SynchronizedCollectionsSerializer.registerSerializers(kryo);
// Serialize inner AbstractList$SubAbstractListRandomAccess
kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(),
new NoArgCollectionSerializer());
// Serialize AbstractList$SubAbstractList
kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(),
new NoArgCollectionSerializer());
// To keep backward compatibility don't change the order of serializers above
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}
示例7: newClientConfig
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
public Config newClientConfig() {
ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
customizeKryo(kryo);
return kryo;
}
};
Config config = new Config();
config.host = "localhost";
config.port = 15150;
config.bindPort = 0;
config.connectTimeout = 10000;
config.serialiser = new KryoSerialiser(new SerialiserConfig(), kryos);
config.udpPeerClass = JavaNetPeer.class;
// config.udpPeer = new KryoNettyPeer(config);
config.externalReceiver = message1 -> message1.process(null);
config.keepAliveInterval = 700;
config.getAdditionalConfig(MessageLogProcessor.ProcessorConfig.class).messageLogReceiveFilter = message -> true;
config.compressBigMessages = true;
config.autoSplitTooBigMessages = true;
return (config);
}
示例8: createKryoInstance
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
private Kryo createKryoInstance(boolean compatibilityMode) {
Kryo kryo = new Kryo();
if (compatibilityMode) {
kryo.getFieldSerializerConfig().setOptimizedGenerics(true);
}
kryo.register(PaperTable.class);
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
kryo.setReferences(false);
// Serialize Arrays$ArrayList
//noinspection ArraysAsListWithZeroOrOneArgument
kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
UnmodifiableCollectionsSerializer.registerSerializers(kryo);
SynchronizedCollectionsSerializer.registerSerializers(kryo);
// Serialize inner AbstractList$SubAbstractListRandomAccess
kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(),
new NoArgCollectionSerializer());
// Serialize AbstractList$SubAbstractList
kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(),
new NoArgCollectionSerializer());
// To keep backward compatibility don't change the order of serializers above
// UUID support
kryo.register(UUID.class, new UUIDSerializer());
for (Class<?> clazz : mCustomSerializers.keySet())
kryo.register(clazz, mCustomSerializers.get(clazz));
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}
示例9: read
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
/**
* Utility method to read any object written with
* {@link #write(Object, DataOutput)}.
*
* @param <T>
* type of object
* @param in
* input
* @return the object
* @throws IOException
*/
@SuppressWarnings("unchecked")
public static <T> T read(DataInput in) throws IOException {
final int length = in.readInt();
final byte[] bytes = new byte[length];
in.readFully(bytes);
final Kryo kryo = new Kryo();
Object obj;
try {
obj = kryo.readClassAndObject(new Input(bytes));
} catch (final KryoException e) {
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
obj = kryo.readClassAndObject(new Input(bytes));
}
return (T) obj;
}
示例10: tesstByteBuf
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
public void tesstByteBuf() throws InterruptedException, IOException {
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
ClassPath from = ClassPath.from(systemClassLoader);
StdInstantiatorStrategy instantiator = new StdInstantiatorStrategy();
Class<Request> requestClazz = Request.class;
for (ClassPath.ClassInfo clazz : from.getAllClasses()) {
Class<?> load;
try {
load = clazz.load();
} catch (NoClassDefFoundError e) {
continue;
}
for (Class<?> aClass : load.getInterfaces()) {
if (aClass.equals(requestClazz)) {
Object o = instantiator.newInstantiatorOf(aClass).newInstance();
testByteBuf((Request) o);
}
}
}
}
示例11: initKryo
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
/**
* 根据所注册的Class,初始化Kryo实例
*
* @return
*/
protected Kryo initKryo() {
Kryo kryo = new Kryo();
kryo.setReferences(true);
kryo.setRegistrationRequired(true);
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
Set<Class<?>> keys = propertyMap.keySet();
for(Class<?> key : keys){
if(propertyMap.get(key) != null){
kryo.register(key, propertyMap.get(key));
} else {
kryo.register(key);
}
}
return kryo;
}
示例12: _Serialize
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
private ByteArrayOutputStream _Serialize(Object obj) throws Exception {
// TODO Auto-generated method stub
if(obj instanceof Serializable){
this.className = obj.getClass();
Kryo kryo = new Kryo();
kryo.setReferences(true);
kryo.setRegistrationRequired(true);
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
kryo.register(obj.getClass(), this.serializer);
kryo.register(this.serializer.getClass());
Output output = null;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
try{
output = new Output(outStream);
kryo.writeClassAndObject(output, obj);
output.flush();
return outStream;
} finally {
output.close();
kryo = null;
}
} else {
throw new Exception("欲序列化的对象请实现Serializable接口");
}
}
示例13: Deserialize
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
@Override
public Object Deserialize(byte[] aryByte) throws Exception {
Kryo kryo = new Kryo();
kryo.setReferences(true);
kryo.setRegistrationRequired(true);
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
kryo.register(this.className, this.serializer);
Input input = null;
try {
input = new Input(new ByteArrayInputStream(aryByte));
Object obj = kryo.readClassAndObject(input);
return obj;
} finally {
if(input != null){
input.close();
}
kryo = null;
}
}
示例14: readObject
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
public static Object readObject(InputStream inputStream) {
Kryo kryo = new Kryo();
kryo.register(java.lang.invoke.SerializedLambda.class);
kryo.register(ClosureSerializer.Closure.class, new ClosureSerializer());
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
Input input = new Input(inputStream);
return kryo.readClassAndObject(input);
}
示例15: initialValue
import org.objenesis.strategy.StdInstantiatorStrategy; //导入依赖的package包/类
@Override
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}