コード例 #1
0
 /// <summary>Stores the item in the configuration with the given keyName.</summary>
 /// <?/>
 /// <param name="conf">the configuration to store</param>
 /// <param name="item">the object to be stored</param>
 /// <param name="keyName">the name of the key to use</param>
 /// <exception cref="System.IO.IOException">
 /// : forwards Exceptions from the underlying
 /// <see cref="Org.Apache.Hadoop.IO.Serializer.Serialization{T}"/>
 /// classes.
 /// </exception>
 public static void Store <K>(Configuration conf, K item, string keyName)
 {
     Org.Apache.Hadoop.IO.DefaultStringifier <K> stringifier = new Org.Apache.Hadoop.IO.DefaultStringifier
                                                               <K>(conf, GenericsUtil.GetClass(item));
     conf.Set(keyName, stringifier.ToString(item));
     stringifier.Close();
 }
コード例 #2
0
 /// <summary>Stores the array of items in the configuration with the given keyName.</summary>
 /// <?/>
 /// <param name="conf">the configuration to use</param>
 /// <param name="items">the objects to be stored</param>
 /// <param name="keyName">the name of the key to use</param>
 /// <exception cref="System.IndexOutOfRangeException">if the items array is empty</exception>
 /// <exception cref="System.IO.IOException">
 /// : forwards Exceptions from the underlying
 /// <see cref="Org.Apache.Hadoop.IO.Serializer.Serialization{T}"/>
 /// classes.
 /// </exception>
 public static void StoreArray <K>(Configuration conf, K[] items, string keyName)
 {
     Org.Apache.Hadoop.IO.DefaultStringifier <K> stringifier = new Org.Apache.Hadoop.IO.DefaultStringifier
                                                               <K>(conf, GenericsUtil.GetClass(items[0]));
     try
     {
         StringBuilder builder = new StringBuilder();
         foreach (K item in items)
         {
             builder.Append(stringifier.ToString(item)).Append(Separator);
         }
         conf.Set(keyName, builder.ToString());
     }
     finally
     {
         stringifier.Close();
     }
 }
コード例 #3
0
ファイル: Chain.cs プロジェクト: orf53975/hadoop.net
            /// <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);
            }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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);
        }