/// <exception cref="System.IO.IOException"/> public virtual void Close() { inBuf.Close(); outBuf.Close(); deserializer.Close(); serializer.Close(); }
/// <exception cref="System.IO.IOException"/> private E MakeCopyForPassByValue <E>(Serialization <E> serialization, E obj) { Org.Apache.Hadoop.IO.Serializer.Serializer <E> ser = serialization.GetSerializer(GenericsUtil .GetClass(obj)); Deserializer <E> deser = serialization.GetDeserializer(GenericsUtil.GetClass(obj)); DataOutputBuffer dof = this._enclosing.threadLocalDataOutputBuffer.Get(); dof.Reset(); ser.Open(dof); ser.Serialize(obj); ser.Close(); obj = ReflectionUtils.NewInstance(GenericsUtil.GetClass(obj), this._enclosing.GetChainJobConf ()); ByteArrayInputStream bais = new ByteArrayInputStream(dof.GetData(), 0, dof.GetLength ()); deser.Open(bais); deser.Deserialize(obj); deser.Close(); return(obj); }
/// <summary>A utility that tests serialization/deserialization.</summary> /// <param name="conf"> /// configuration to use, "io.serializations" is read to /// determine the serialization /// </param> /// <?/> /// <param name="before">item to (de)serialize</param> /// <returns>deserialized item</returns> /// <exception cref="System.Exception"/> public static K TestSerialization <K>(Configuration conf, K before) { SerializationFactory factory = new SerializationFactory(conf); Org.Apache.Hadoop.IO.Serializer.Serializer <K> serializer = factory.GetSerializer( GenericsUtil.GetClass(before)); Deserializer <K> deserializer = factory.GetDeserializer(GenericsUtil.GetClass(before )); DataOutputBuffer @out = new DataOutputBuffer(); serializer.Open(@out); serializer.Serialize(before); serializer.Close(); DataInputBuffer @in = new DataInputBuffer(); @in.Reset(@out.GetData(), @out.GetLength()); deserializer.Open(@in); K after = deserializer.Deserialize(null); deserializer.Close(); return(after); }
public virtual void TestWritableComparatorJavaSerialization() { Serialization ser = new JavaSerialization(); Org.Apache.Hadoop.IO.Serializer.Serializer <TestWritableSerialization.TestWC> serializer = ser.GetSerializer(typeof(TestWritableSerialization.TestWC)); DataOutputBuffer dob = new DataOutputBuffer(); serializer.Open(dob); TestWritableSerialization.TestWC orig = new TestWritableSerialization.TestWC(0); serializer.Serialize(orig); serializer.Close(); Deserializer <TestWritableSerialization.TestWC> deserializer = ser.GetDeserializer (typeof(TestWritableSerialization.TestWC)); DataInputBuffer dib = new DataInputBuffer(); dib.Reset(dob.GetData(), 0, dob.GetLength()); deserializer.Open(dib); TestWritableSerialization.TestWC deser = deserializer.Deserialize(null); deserializer.Close(); Assert.Equal(orig, deser); }
/// <exception cref="System.Exception"/> private K SerDeser <K>(K conf) { SerializationFactory factory = new SerializationFactory(Conf); Org.Apache.Hadoop.IO.Serializer.Serializer <K> serializer = factory.GetSerializer( GenericsUtil.GetClass(conf)); Deserializer <K> deserializer = factory.GetDeserializer(GenericsUtil.GetClass(conf )); DataOutputBuffer @out = new DataOutputBuffer(); serializer.Open(@out); serializer.Serialize(conf); serializer.Close(); DataInputBuffer @in = new DataInputBuffer(); @in.Reset(@out.GetData(), @out.GetLength()); deserializer.Open(@in); K after = deserializer.Deserialize(null); deserializer.Close(); return(after); }