com.esotericsoftware.kryo.Kryo.copy()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中com.esotericsoftware.kryo.Kryo.copy()方法的一些代码示例,展示了Kryo.copy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.copy()方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:copy

Kryo.copy介绍

[英]Returns a deep copy of the object. Serializers for the classes involved must support Serializer#copy(Kryo,Object).
[中]返回对象的深度副本。涉及的类的序列化程序必须支持序列化程序#copy(Kryo,Object)。

代码示例

代码示例来源:origin: changmingxie/tcc-transaction

public T execute(Kryo kryo) {
    return kryo.copy(object);
  }
});

代码示例来源:origin: changmingxie/tcc-transaction

@Override
  public T clone(T object) {
    return getInstance().copy(object);
  }
}

代码示例来源:origin: changmingxie/tcc-transaction

@Override
  public T clone(T object) {
    return getInstance().copy(object);
  }
}

代码示例来源:origin: orbit/orbit

@Override
  public <T> T clone(final T object)
  {
    if (object != null)
    {
      return kryoPool.run(kryo -> kryo.copy(object));
    }
    return null;
  }
}

代码示例来源:origin: apache/hive

@Override
 public List<?> copy(final Kryo kryo, final List<?> original) {
  try {
    kryo.reference(FAKE_REFERENCE);
    final List<?> list = (List<?>) _parentField.get(original);
    final int parentOffset = _parentOffsetField.getInt( original );
    final int fromIndex = parentOffset;
    final int toIndex = fromIndex + _sizeField.getInt( original );
    return kryo.copy(list).subList(fromIndex, toIndex);
  } catch (final Exception e) {
      throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: apache/flink

/**
 * Tries to copy the given record from using the provided Kryo instance. If this fails, then
 * the record from is copied by serializing it into a byte buffer and deserializing it from
 * there.
 *
 * @param from Element to copy
 * @param kryo Kryo instance to use
 * @param serializer TypeSerializer which is used in case of a Kryo failure
 * @param <T> Type of the element to be copied
 * @return Copied element
 */
public static <T> T copy(T from, Kryo kryo, TypeSerializer<T> serializer) {
  try {
    return kryo.copy(from);
  } catch (KryoException ke) {
    // Kryo could not copy the object --> try to serialize/deserialize the object
    try {
      byte[] byteArray = InstantiationUtil.serializeToByteArray(serializer, from);
      return InstantiationUtil.deserializeFromByteArray(serializer, byteArray);
    } catch (IOException ioe) {
      throw new RuntimeException("Could not copy object by serializing/deserializing" +
        " it.", ioe);
    }
  }
}

代码示例来源:origin: apache/flink

/**
 * Tries to copy the given record from using the provided Kryo instance. If this fails, then
 * the record from is copied by serializing it into a byte buffer and deserializing it from
 * there.
 *
 * @param from Element to copy
 * @param reuse Reuse element for the deserialization
 * @param kryo Kryo instance to use
 * @param serializer TypeSerializer which is used in case of a Kryo failure
 * @param <T> Type of the element to be copied
 * @return Copied element
 */
public static <T> T copy(T from, T reuse, Kryo kryo, TypeSerializer<T> serializer) {
  try {
    return kryo.copy(from);
  } catch (KryoException ke) {
    // Kryo could not copy the object --> try to serialize/deserialize the object
    try {
      byte[] byteArray = InstantiationUtil.serializeToByteArray(serializer, from);
      return InstantiationUtil.deserializeFromByteArray(serializer, reuse, byteArray);
    } catch (IOException ioe) {
      throw new RuntimeException("Could not copy object by serializing/deserializing" +
        " it.", ioe);
    }
  }
}

代码示例来源:origin: apache/flink

checkKryoInitialized();
try {
  return kryo.copy(from);

代码示例来源:origin: apache/hive

private ByteBuffer getSerializedSargForMetastore(boolean isOriginal) {
 if (sarg == null) {
  return null;
 }
 ByteBuffer serializedSarg = isOriginal ? sargIsOriginal : sargNotIsOriginal;
 if (serializedSarg != null) {
  return serializedSarg;
 }
 SearchArgument sarg2 = sarg;
 Kryo kryo = SerializationUtilities.borrowKryo();
 try {
  if ((isOriginal ? sargNotIsOriginal : sargIsOriginal) == null) {
   sarg2 = kryo.copy(sarg2); // In case we need it for the other case.
  }
  translateSargToTableColIndexes(sarg2, conf, OrcInputFormat.getRootColumn(isOriginal));
  ExternalCache.Baos baos = new Baos();
  Output output = new Output(baos);
  kryo.writeObject(output, sarg2);
  output.flush();
  serializedSarg = baos.get();
  if (isOriginal) {
   sargIsOriginal = serializedSarg;
  } else {
   sargNotIsOriginal = serializedSarg;
  }
 } finally {
  SerializationUtilities.releaseKryo(kryo);
 }
 return serializedSarg;
}

代码示例来源:origin: inspectIT/inspectIT

/**
 * {@inheritDoc}
 */
@Override
public <T> T copy(T object) {
  return kryo.copy(object);
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

public Object[] copy (Kryo kryo, Object[] original) {
  Object[] copy = (Object[]) Array.newInstance(original.getClass().getComponentType(), original.length);
  for (int i = 0, n = original.length; i < n; i++)
    copy[i] = kryo.copy(original[i]);
  return copy;
}

代码示例来源:origin: com.esotericsoftware/kryo

@Override
  public Optional copy (Kryo kryo, Optional original) {
    if (original.isPresent()) {
      return Optional.of(kryo.copy(original.get()));
    }
    return original;
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

public Object[] copy (Kryo kryo, Object[] original) {
  Object[] copy = (Object[])Array.newInstance(original.getClass().getComponentType(), original.length);
  for (int i = 0, n = original.length; i < n; i++)
    copy[i] = kryo.copy(original[i]);
  return copy;
}

代码示例来源:origin: com.esotericsoftware/kryo

public Map copy (Kryo kryo, Map original) {
  Map copy = createCopy(kryo, original);
  for (Iterator iter = original.entrySet().iterator(); iter.hasNext();) {
    Entry entry = (Entry)iter.next();
    copy.put(kryo.copy(entry.getKey()), kryo.copy(entry.getValue()));
  }
  return copy;
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

public Map copy (Kryo kryo, Map original) {
  Map copy = createCopy(kryo, original);
  for (Iterator iter = original.entrySet().iterator(); iter.hasNext();) {
    Entry entry = (Entry)iter.next();
    copy.put(kryo.copy(entry.getKey()), kryo.copy(entry.getValue()));
  }
  return copy;
}

代码示例来源:origin: stratosphere/stratosphere

@Override
public void setReference(T toCompare) {
  checkKryoInitialized();
  reference = this.kryo.copy(toCompare);
}

代码示例来源:origin: stratosphere/stratosphere

@Override
public void setReference(T toCompare) {
  checkKryoInitialized();
  reference = this.kryo.copy(toCompare);
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

public Collection copy (Kryo kryo, Collection original) {
  Collection copy = createCopy(kryo, original);
  kryo.reference(copy);
  for (Object element : original)
    copy.add(kryo.copy(element));
  return copy;
}

代码示例来源:origin: com.esotericsoftware/kryo

public Collection copy (Kryo kryo, Collection original) {
  Collection copy = createCopy(kryo, original);
  kryo.reference(copy);
  for (Object element : original)
    copy.add(kryo.copy(element));
  return copy;
}

代码示例来源:origin: vmware/xenon

public static <T> T cloneObject(T t) {
  Kryo k = getKryoThreadLocalForObjects();
  T clone = k.copy(t);
  k.reset();
  return clone;
}

相关文章