當前位置: 首頁>>代碼示例>>Java>>正文


Java Kryo.newInstance方法代碼示例

本文整理匯總了Java中com.esotericsoftware.kryo.Kryo.newInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Kryo.newInstance方法的具體用法?Java Kryo.newInstance怎麽用?Java Kryo.newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.esotericsoftware.kryo.Kryo的用法示例。


在下文中一共展示了Kryo.newInstance方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: forSerialization

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的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);
    }

  };
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:23,代碼來源:KryoLogicalPlanSerializers.java

示例2: read

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public RelTraitSet read(final Kryo kryo, final Input input, final Class<RelTraitSet> type) {

  final int size = kryo.readObject(input, Integer.class);
  final RelTrait[] traits = new RelTrait[size];
  for (int i = 0; i < size; i++) {
    final RelTrait trait = (RelTrait) kryo.readClassAndObject(input);
    // normalize trait so that stupid calcite won't complain about == checks.
    traits[i] = trait.getTraitDef().canonize(trait);
  }

  final String digest = kryo.readObject(input, String.class);
  final Object cache = kryo.readClassAndObject(input);

  final RelTraitSet traitSet = kryo.newInstance(type);

  try {
    getField(NAME_CACHE).set(traitSet, cache);
    getField(NAME_TRAITS).set(traitSet, traits);
    getField(NAME_STRING).set(traitSet, digest);
  } catch (final NoSuchFieldException|IllegalAccessException e) {
    throw new RuntimeException("unable to deserialize TraitSet", e);
  }

  kryo.reference(traitSet);
  return traitSet;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:28,代碼來源:RelTraitSerializers.java

示例3: read

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  // do not use delegate.read because we do not want it to cache the object. Rather, we will cache the normalized type.
  final T dataType = kryo.newInstance(type);
  final FieldSerializer.CachedField[] fields = delegate.getFields();
  for (int i = 0, n = fields.length; i < n; i++) {
    fields[i].read(input, dataType);
  }

  // be gentle to calcite and normalize the returned data type. normalization here means to use same type instances.
  final T result = (T) typeFactory.copyType(dataType);
  kryo.reference(result);
  return result;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:15,代碼來源:RelDataTypeSerializer.java

示例4: read

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  try {
    final T object = kryo.newInstance(type);
    kryo.reference(object);
    object.readFields(new DataInputStream(input));
    return object;
  } catch (final IOException e) {
    throw new RuntimeException("unable to deserialize Writable object", e);
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:12,代碼來源:WritableSerializer.java

示例5: read

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public T read(Kryo kryo, Input input, Class<T> type) {
    int nfields = input.readInt(true);
    T object = kryo.newInstance(type);
    for(int i = 0; i < nfields; i++) {
        int id = input.readInt(true);
        try {
            fields.get(id).set(object, kryo.readClassAndObject(input));
        } catch(IllegalAccessException e) {
            throw new AssertionError(e);
        }
    }
    return object;
}
 
開發者ID:natanbc,項目名稱:GabrielBot,代碼行數:15,代碼來源:CustomSerializer.java


注:本文中的com.esotericsoftware.kryo.Kryo.newInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。