HashMap deserialization issues in Android

I am serializing a HashMap on my PC application using the following code:

private void serialize(HashMap<Integer, Integer> map2write, String name_ser)
{// serializes fphlist into .ser file called name_ser
    FileOutputStream fileOut = null;
    try {
        fileOut = new FileOutputStream(project_dir + "/" + name_ser + ".ser");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(AdminConsoleUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    ObjectOutputStream out;
    try {
        out = new ObjectOutputStream(fileOut);
        out.writeObject(map2write);
        out.reset();
        out.flush();
        out.close();
        fileOut.close();

    } catch (IOException ex) {
        Logger.getLogger(AdminConsoleUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}

Then I de-serialize it in my Android app using this code:

private HashMap<Integer,Integer> deserialize_Map(String fn)
{// deserializes fn into HashMap

    HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
    try
    {
        FileInputStream fileIn = new FileInputStream(project_dir + "/" + fn + ".ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        hm = (HashMap<Integer,Integer>) in.readObject();
        in.close();
        fileIn.close();

   }catch(IOException i)
   {
       Log.e("MYAPP", "exception", i);
       return null;
   }catch(ClassNotFoundException c)
   {
       Log.e("MYAPP", "exception", c);
       return null;
   }catch(ClassCastException ex)
   {
       Log.e("MYAPP", "exception", ex);
       return null;
   }

    return hm;
}

In the end, I ran into two problems.

1) Decontamination takes a very long time. It contains about a thousand keys, is that normal? Is there a more efficient serialization method to solve this problem?

2) After deserialization, I get a hashmap that takes almost twice as much as it originally takes on the VM, and when I check it in the debugger, it has many null entries between the key values ​​that it should initially contain. However, they are not null keys, but simply null, and I can’t see what is inside them. I am debugging Eclipse. Why is this going to happen?

+5
2

1) "" HashMap VM? , ( -, - ) . sqlite - . , , , .

init, , , HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>(SIZE*2);

2.

HashMap , : . - -, - -. - , - , . - , ,

+3

HashMap JSON? Android JSON .

+4

All Articles