Example #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();
 }
Example #2
0
 /// <summary>Restores the object from the configuration.</summary>
 /// <?/>
 /// <param name="conf">the configuration to use</param>
 /// <param name="keyName">the name of the key to use</param>
 /// <param name="itemClass">the class of the item</param>
 /// <returns>restored object</returns>
 /// <exception cref="System.IO.IOException">
 /// : forwards Exceptions from the underlying
 /// <see cref="Org.Apache.Hadoop.IO.Serializer.Serialization{T}"/>
 /// classes.
 /// </exception>
 public static K Load <K>(Configuration conf, string keyName)
 {
     System.Type itemClass = typeof(K);
     Org.Apache.Hadoop.IO.DefaultStringifier <K> stringifier = new Org.Apache.Hadoop.IO.DefaultStringifier
                                                               <K>(conf, itemClass);
     try
     {
         string itemStr = conf.Get(keyName);
         return(stringifier.FromString(itemStr));
     }
     finally
     {
         stringifier.Close();
     }
 }
Example #3
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();
     }
 }
Example #4
0
 /// <summary>Restores the array of objects from the configuration.</summary>
 /// <?/>
 /// <param name="conf">the configuration to use</param>
 /// <param name="keyName">the name of the key to use</param>
 /// <param name="itemClass">the class of the item</param>
 /// <returns>restored object</returns>
 /// <exception cref="System.IO.IOException">
 /// : forwards Exceptions from the underlying
 /// <see cref="Org.Apache.Hadoop.IO.Serializer.Serialization{T}"/>
 /// classes.
 /// </exception>
 public static K[] LoadArray <K>(Configuration conf, string keyName)
 {
     System.Type itemClass = typeof(K);
     Org.Apache.Hadoop.IO.DefaultStringifier <K> stringifier = new Org.Apache.Hadoop.IO.DefaultStringifier
                                                               <K>(conf, itemClass);
     try
     {
         string    itemStr = conf.Get(keyName);
         AList <K> list    = new AList <K>();
         string[]  parts   = itemStr.Split(Separator);
         foreach (string part in parts)
         {
             if (!part.IsEmpty())
             {
                 list.AddItem(stringifier.FromString(part));
             }
         }
         return(GenericsUtil.ToArray(itemClass, list));
     }
     finally
     {
         stringifier.Close();
     }
 }