示例#1
0
 public static void CloneWritableInto(IWritable dst, IWritable src)
 {
     ReflectionUtils.CopyInCopyOutBuffer buffer = cloneBuffers.Get();
     buffer.outBuffer.Reset();
     src.Write(buffer.outBuffer);
     buffer.MoveData();
     dst.ReadFields(buffer.inBuffer);
 }
示例#2
0
        /// <summary>Make a copy of the writable object using serialization to a buffer</summary>
        /// <param name="src">the object to copy from</param>
        /// <param name="dst">the object to copy into, which is destroyed</param>
        /// <returns>dst param (the copy)</returns>
        /// <exception cref="System.IO.IOException"/>
        public static T Copy <T>(Configuration conf, T src, T dst)
        {
            ReflectionUtils.CopyInCopyOutBuffer buffer = cloneBuffers.Get();
            buffer.outBuffer.Reset();
            SerializationFactory factory = GetFactory(conf);
            Type cls = (Type)src.GetType();

            Org.Apache.Hadoop.IO.Serializer.Serializer <T> serializer = factory.GetSerializer(
                cls);
            serializer.Open(buffer.outBuffer);
            serializer.Serialize(src);
            buffer.MoveData();
            Deserializer <T> deserializer = factory.GetDeserializer(cls);

            deserializer.Open(buffer.inBuffer);
            dst = deserializer.Deserialize(dst);
            return(dst);
        }