From 03a68efe7c3de70f949502547643d620cb128590 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sun, 7 Apr 2002 23:15:29 +0000 Subject: [PATCH] Switched to doing serialization by hand because I got tired of Java's fucking serialization crapping out when the class was recompiled and its panties got into a bunch. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1216 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../bundle/tools/ComponentBundlerTask.java | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java b/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java index 5aef3f16c..2e3a2e91a 100644 --- a/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java +++ b/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java @@ -1,18 +1,22 @@ // -// $Id: ComponentBundlerTask.java,v 1.6 2002/04/01 16:49:26 mdb Exp $ +// $Id: ComponentBundlerTask.java,v 1.7 2002/04/07 23:15:29 mdb Exp $ package com.threerings.cast.bundle.tools; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.jar.JarOutputStream; import java.util.jar.JarEntry; @@ -225,16 +229,16 @@ public class ComponentBundlerTask extends Task protected HashMapIDBroker loadBroker (File mapfile) throws BuildException { - HashMapIDBroker broker; + HashMapIDBroker broker = new HashMapIDBroker(); try { FileInputStream fin = new FileInputStream(mapfile); - ObjectInputStream oin = new ObjectInputStream(fin); - broker = (HashMapIDBroker)oin.readObject(); + DataInputStream din = + new DataInputStream(new BufferedInputStream(fin)); + broker.readFrom(din); } catch (FileNotFoundException fnfe) { // if the file doesn't yet exist, start with a blank broker - broker = new HashMapIDBroker(); } catch (Exception e) { throw new BuildException("Error loading component ID map " + @@ -253,9 +257,10 @@ public class ComponentBundlerTask extends Task { try { FileOutputStream fout = new FileOutputStream(mapfile); - ObjectOutputStream oout = new ObjectOutputStream(fout); - oout.writeObject(broker); - oout.close(); + DataOutputStream dout = + new DataOutputStream(new BufferedOutputStream(fout)); + ((HashMapIDBroker)broker).writeTo(dout); + dout.close(); } catch (IOException ioe) { throw new BuildException("Unable to store component ID map " + "[mapfile=" + mapfile + "]", ioe); @@ -283,6 +288,40 @@ public class ComponentBundlerTask extends Task // nothing doing } + public void writeTo (DataOutputStream dout) + throws IOException + { + // write out the size of the table + dout.writeInt(size()); + // write out the keys and values + Iterator keys = keySet().iterator(); + while (keys.hasNext()) { + Tuple key = (Tuple)keys.next(); + Integer value = (Integer)get(key); + dout.writeUTF((String)key.left); + dout.writeUTF((String)key.right); + dout.writeInt(value.intValue()); + } + // write out our most recently assigned component id + dout.writeInt(_nextCID); + } + + public void readFrom (DataInputStream din) + throws IOException + { + // figure out how many keys and values we'll be reading + int size = din.readInt(); + // and read them on in + for (int i = 0; i < size; i++) { + String cclass = din.readUTF(); + String cname = din.readUTF(); + int value = din.readInt(); + put(new Tuple(cclass, cname), new Integer(value)); + } + // read in our most recently assigned component id + _nextCID = din.readInt(); + } + protected int _nextCID = 0; }