/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.network.URL; /* */ import java.io.DataOutput; /* */ import java.io.DataOutputStream; /* */ import java.io.File; /* */ import java.io.FileOutputStream; /* */ import java.io.IOException; /* */ import java.util.Enumeration; /* */ import java.util.Hashtable; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class Saver /* */ { /* */ static final String headerString = "PERSISTER Worlds, Inc."; /* */ static final String trailerString = "END PERSISTER"; /* 87 */ private static int _version = 7; /* */ private DataOutput os; /* */ private boolean myFile; /* */ private Hashtable, Class> classTable; /* */ /* */ public static int version() /* */ { /* 94 */ return _version; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private Hashtable objectTable; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private Hashtable cookieTable; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private URL reference; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public URL getReferenceURL() /* */ { /* 139 */ return this.reference; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public Saver(URL url) /* */ throws IOException /* */ { /* 149 */ this(new DataOutputStream(new FileOutputStream(new File( /* 150 */ url.unalias())))); /* 151 */ this.reference = url; /* */ /* */ /* 154 */ this.myFile = true; /* */ } /* */ /* */ /* */ /* */ /* */ public Saver(DataOutput os) /* */ throws IOException /* */ { /* 163 */ this.os = os; /* */ /* */ /* 166 */ saveString("PERSISTER Worlds, Inc."); /* 167 */ saveInt(_version); /* */ /* 169 */ this.classTable = new Hashtable(); /* 170 */ this.objectTable = new Hashtable(); /* 171 */ this.cookieTable = new Hashtable(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void saveVersion(int v, Object cookie) /* */ throws IOException /* */ { /* 188 */ Integer oldv = (Integer)this.cookieTable.get(cookie); /* 189 */ if (oldv == null) { /* 190 */ saveInt(v); /* 191 */ this.cookieTable.put(cookie, new Integer(v)); /* */ } /* */ else { /* 194 */ assert (oldv.intValue() == v); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ public void save(Persister p) /* */ throws IOException /* */ { /* 204 */ assert (!(p instanceof NonPersister)); /* */ /* */ /* 207 */ int hashed = UniqueHasher.uh().hash(p); /* 208 */ saveInt(hashed); /* */ /* 210 */ if (this.objectTable.containsKey(p)) /* */ { /* 212 */ return; /* */ } /* */ /* */ /* */ /* */ /* */ /* 219 */ this.objectTable.put(p, p); /* */ /* */ /* 222 */ saveClass(p.getClass()); /* */ /* 224 */ p.saveState(this); /* */ } /* */ /* */ public void saveVectorMaybeNull(Vector v) /* */ throws IOException /* */ { /* 230 */ if (v == null) { /* 231 */ saveBoolean(false); /* */ } else { /* 233 */ saveBoolean(true); /* 234 */ saveVector(v); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ public void saveMaybeNull(Persister p) /* */ throws IOException /* */ { /* 244 */ if ((p == null) || ((p instanceof NonPersister))) { /* 245 */ saveBoolean(true); /* */ } else { /* 247 */ saveBoolean(false); /* 248 */ save(p); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void saveClass(Class c) /* */ throws IOException /* */ { /* 263 */ UniqueHasher uh = UniqueHasher.uh(); /* */ /* 265 */ saveInt(uh.hash(c.toString())); /* */ /* */ /* 268 */ if (!this.classTable.containsKey(c)) /* */ { /* 270 */ saveString(c.getName()); /* */ /* 272 */ this.classTable.put(c, c); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public void saveArray(Persister[] pa) /* */ throws IOException /* */ { /* 283 */ saveClass(pa.getClass()); /* 284 */ saveInt(pa.length); /* 285 */ for (int i = 0; i < pa.length; i++) /* */ { /* 287 */ saveMaybeNull(pa[i]); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void saveVector(Vector v) /* */ throws IOException /* */ { /* 300 */ synchronized (v) /* */ { /* 302 */ Enumeration en = v.elements(); /* 303 */ int length = 0; /* 304 */ while (en.hasMoreElements()) { /* 305 */ Object obj = en.nextElement(); /* 306 */ if (((obj instanceof Persister)) && (!(obj instanceof NonPersister))) { /* 307 */ length++; /* */ } /* */ } /* 310 */ saveInt(length); /* */ /* 312 */ en = v.elements(); /* 313 */ while (en.hasMoreElements()) { /* 314 */ Object obj = en.nextElement(); /* 315 */ if (((obj instanceof Persister)) && (!(obj instanceof NonPersister))) { /* 316 */ save((Persister)obj); /* */ } /* */ } /* */ } /* */ } /* */ /* */ public void saveString(String str) throws IOException /* */ { /* 324 */ saveBoolean(str == null); /* 325 */ if (str != null) { /* 326 */ this.os.writeUTF(str); /* */ } /* */ } /* */ /* */ public void saveBoolean(boolean b) throws IOException { /* 331 */ this.os.writeBoolean(b); /* */ } /* */ /* */ public void saveByte(byte b) throws IOException { /* 335 */ this.os.writeByte(b); /* */ } /* */ /* */ public void saveShort(short s) throws IOException { /* 339 */ this.os.writeShort(s); /* */ } /* */ /* */ public void saveInt(int i) throws IOException { /* 343 */ this.os.writeInt(i); /* */ } /* */ /* */ public void saveLong(long g) throws IOException { /* 347 */ this.os.writeLong(g); /* */ } /* */ /* */ public void saveFloat(float f) throws IOException { /* 351 */ this.os.writeFloat(f); /* */ } /* */ /* */ public void saveDouble(double d) throws IOException { /* 355 */ this.os.writeDouble(d); /* */ } /* */ /* */ public void done() /* */ throws IOException /* */ { /* 361 */ saveString("END PERSISTER"); /* */ /* */ /* 364 */ if (this.myFile) /* 365 */ ((DataOutputStream)this.os).close(); /* 366 */ this.classTable = null; /* 367 */ this.objectTable = null; /* 368 */ this.cookieTable = null; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\Saver.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */