Skip to content

Instantly share code, notes, and snippets.

@gbonk
Created June 7, 2017 14:49
Show Gist options
  • Save gbonk/c3eb2522d4824f0867de669146afe86e to your computer and use it in GitHub Desktop.
Save gbonk/c3eb2522d4824f0867de669146afe86e to your computer and use it in GitHub Desktop.
example in java of how to serialize and de-serialize a hashtable
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Hashtable;
public class StringInt {
public static void main(String[] args) {
Hashtable<String, Integer> ht = new Hashtable<String, Integer>();
ht.put("Key", 1);
ht.put("Greg", 4);
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(ht);
System.out.println(bos.toString());
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bis);
Object object = in.readObject();
out.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@gbonk
Copy link
Author

gbonk commented Jun 7, 2017

This dumps out...

¬í �sr �java.util.Hashtable�»�%!Jä¸� �F 
loadFactorI 	thresholdxp?@     �w�   �   �t �Keysr �java.lang.Integer�â ¤÷�‡8� �I �valuexr �java.lang.Number†¬•��”à‹�  xp   �t �Gregsq ~ �   �x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment