Code example for ObjectOutputStream

Methods: defaultWriteObject, writeInt, writeObject

0
    private ElementDictionary(int initialCapacity) {
        this.table = new IntHashtable<String>(initialCapacity);
    } 
 
    private void writeObject(final ObjectOutputStream os) throws IOException {
        os.defaultWriteObject();
        os.writeObject(tagClassName);
        os.writeObject(privateCreator);
        os.writeInt(table.size());
        try { 
            table.accept(new IntHashtable.Visitor() {
                public boolean visit(int key, Object value) {
                    try { 
                        os.writeInt(key);
                        os.writeUTF((String) value);
                        return true; 
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } 
                } 
            });