All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.Util.SerializationUtility Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package Alachisoft.NCache.Common.Util;

import com.alachisoft.ncache.serialization.core.io.NCacheObjectInput;
import com.alachisoft.ncache.serialization.core.io.NCacheObjectOutput;

import java.io.IOException;
import java.util.HashMap;

public class SerializationUtility {
    public static  void serializeDictionary(java.util.Map dictionary, NCacheObjectOutput writer) throws IOException
    {

        if (dictionary == null)
        {
            writer.writeBoolean(false);
            return;
        }
        else
        {
            writer.writeBoolean(true);
            writer.write(dictionary.size());
            for (java.util.Iterator> i = dictionary.entrySet().iterator(); i.hasNext();)
            {
                writer.writeObject(i.next().getKey());
                writer.writeObject(i.next().getValue());
            }

        }
    }

    /**


     @param reader
     @return
     */
//C# TO JAVA CONVERTER TODO TASK: C# optional parameters are not converted to Java:
//ORIGINAL LINE: public static IDictionary DeserializeDictionary(Runtime.Serialization.IO.CompactReader reader,IEqualityComparer comparer = null)
    public static  java.util.Map deserializeDictionary(NCacheObjectInput reader) throws IOException, ClassNotFoundException

    {
        T key;
        V val;
        boolean flag = reader.readBoolean();

        if (flag)
        {
            java.util.Map dictionary = new HashMap();
            int Length = reader.readInt();
            for (int i = 0; i < Length; i++)
            {
                key = (T)reader.readObject();
                val = (V)reader.readObject();

                dictionary.put(key, val);
            }
            return dictionary;
        }
        else
        {
            return null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy