diff options
Diffstat (limited to 'NET/worlds/scape/URLSelfLoader.java')
| -rw-r--r-- | NET/worlds/scape/URLSelfLoader.java | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/NET/worlds/scape/URLSelfLoader.java b/NET/worlds/scape/URLSelfLoader.java new file mode 100644 index 0000000..2a605cf --- /dev/null +++ b/NET/worlds/scape/URLSelfLoader.java @@ -0,0 +1,300 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.network.URL; +/* */ import java.io.DataInputStream; +/* */ import java.io.FileInputStream; +/* */ import java.io.IOException; +/* */ import java.util.Hashtable; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class URLSelfLoader +/* */ implements BGLoaded +/* */ { +/* 61 */ private static Hashtable<URL, URLSelf> loaded = new Hashtable(); +/* */ +/* 63 */ private static Hashtable<URL, URLSelfLoader> loading = new Hashtable(); +/* */ +/* */ +/* */ +/* */ +/* */ private URL url; +/* */ +/* */ +/* */ +/* */ +/* */ public static void load(URL url, LoadedURLSelf callback) +/* */ { +/* 75 */ load(url, callback, false); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static void load(URL url, LoadedURLSelf callback, boolean isHighPriority) +/* */ { +/* 86 */ URLSelf o = (URLSelf)loaded.get(url); +/* 87 */ if (o != null) { +/* 88 */ o.incRef(); +/* 89 */ callback.loadedURLSelf(o, url, null); +/* 90 */ return; +/* */ } +/* */ +/* */ +/* 94 */ URLSelfLoader cl = (URLSelfLoader)loading.get(url); +/* 95 */ if (cl != null) { +/* 96 */ cl.callbacks.addElement(callback); +/* 97 */ return; +/* */ } +/* */ +/* */ +/* 101 */ new URLSelfLoader(url, callback, isHighPriority); +/* */ } +/* */ +/* */ public static void unload(URLSelf self) { +/* 105 */ loaded.remove(self.getSourceURL()); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static void immediateLoad(IncrementalRestorer o, Restorer r) +/* */ throws IOException, TooNewException +/* */ { +/* 118 */ new URLSelfLoader(o, r); +/* */ } +/* */ +/* */ private URLSelfLoader(IncrementalRestorer o, Restorer r) throws IOException, TooNewException +/* */ { +/* 123 */ this.url = null; +/* */ +/* 125 */ while (this.state != -1) { +/* */ try { +/* 127 */ this.state = o.incRestore(this.state, r, this); +/* */ } catch (Exception e) { +/* 129 */ e.printStackTrace(System.out); +/* 130 */ if (!$assertionsDisabled) { throw new AssertionError(); +/* */ } +/* */ } +/* */ } +/* */ } +/* */ +/* 136 */ private Vector<LoadedURLSelf> callbacks = new Vector(); +/* */ private static final int INIT = 0; +/* */ +/* 139 */ public URL getURL() { return this.url; } +/* */ +/* */ +/* */ private URLSelfLoader(URL url, LoadedURLSelf callback, boolean isHighPriority) +/* */ { +/* 144 */ loading.put(url, this); +/* 145 */ this.url = url; +/* 146 */ this.callbacks.addElement(callback); +/* */ +/* 148 */ BackgroundLoader.get(this, url, isHighPriority); +/* */ } +/* */ +/* */ +/* */ +/* */ private static final int DONE = -1; +/* */ +/* 155 */ private int state = 0; +/* */ +/* */ private DataInputStream inFile; +/* */ +/* */ private Restorer restorer; +/* */ +/* */ private URLSelf loadedObj; +/* */ +/* */ public Object otemp1; +/* */ +/* */ public Object otemp2; +/* */ +/* */ public int itemp1; +/* */ public int itemp2; +/* */ +/* */ public Object asyncBackgroundLoad(String localName, URL remoteName) +/* */ { +/* 172 */ if (localName == null) { +/* 173 */ return "Can't find file " + this.url; +/* */ } +/* */ try { +/* 176 */ return new DataInputStream(new FileInputStream(localName)); +/* */ } catch (IOException e) {} +/* 178 */ return "Can't load file " + this.url; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean syncBackgroundLoad(Object obj, URL remoteURL) +/* */ { +/* 188 */ if ((obj instanceof String)) { +/* 189 */ doneLoading(null, (String)obj); +/* 190 */ return false; +/* */ } +/* */ +/* 193 */ assert (this.state != -1); +/* */ +/* 195 */ if (this.state == 0) +/* */ { +/* 197 */ this.inFile = ((DataInputStream)obj); +/* */ +/* 199 */ Object o = null; +/* */ try { +/* 201 */ this.restorer = new Restorer(this.inFile, this.url); +/* 202 */ o = this.restorer.restore(false); +/* 203 */ this.loadedObj = ((URLSelf)o); +/* */ +/* 205 */ this.loadedObj.setSourceURL(getURL()); +/* */ +/* 207 */ if (!(this.loadedObj instanceof IncrementalRestorer)) { +/* 208 */ this.loadedObj.restoreState(this.restorer); +/* 209 */ this.restorer.done(); +/* 210 */ return doneLoading(this.loadedObj, null); +/* */ } +/* */ } catch (Exception e) { +/* 213 */ e.printStackTrace(System.out); +/* 214 */ return doneLoading(null, "Can't restore from file " + this.url + +/* 215 */ ": " + e.toString()); +/* */ } +/* */ } +/* */ try +/* */ { +/* 220 */ this.state = ((IncrementalRestorer)this.loadedObj).incRestore(this.state, +/* 221 */ this.restorer, this); +/* */ } catch (Exception e) { +/* 223 */ e.printStackTrace(System.out); +/* 224 */ return doneLoading(null, e.toString()); +/* */ } +/* */ +/* 227 */ if (this.state == -1) { +/* */ try { +/* 229 */ this.restorer.done(); +/* */ } catch (IOException e) { +/* 231 */ e.printStackTrace(System.out); +/* 232 */ return doneLoading(null, e.toString()); +/* */ } +/* 234 */ if ((this.restorer.version() < 3) && ((this.loadedObj instanceof Camera))) +/* */ { +/* 236 */ Camera cam = (Camera)this.loadedObj; +/* 237 */ World w = cam.getWorld(); +/* 238 */ w.setSourceURL(cam.getSourceURL()); +/* */ } +/* */ +/* 241 */ return doneLoading(this.loadedObj, null); +/* */ } +/* */ +/* 244 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private boolean doneLoading(URLSelf o, String err) +/* */ { +/* 256 */ if (this.inFile != null) { +/* */ try { +/* 258 */ this.inFile.close(); +/* 259 */ this.inFile = null; +/* */ } catch (Exception ex) { +/* 261 */ this.inFile = null; +/* */ } +/* */ } +/* */ +/* 265 */ loading.remove(this.url); +/* */ +/* */ +/* */ +/* 269 */ if (o != null) { +/* 270 */ if ((this.restorer.version() < 4) && ((o instanceof Camera))) { +/* 271 */ Camera c = (Camera)o; +/* 272 */ o = c.getWorld(); +/* 273 */ c.detach(); +/* */ } +/* */ +/* 276 */ loaded.put(this.url, o); +/* */ } +/* */ +/* 279 */ int end = this.callbacks.size(); +/* 280 */ for (int i = 0; i < end; i++) { +/* 281 */ LoadedURLSelf callback = (LoadedURLSelf)this.callbacks.elementAt(i); +/* 282 */ if (o != null) +/* 283 */ o.incRef(); +/* 284 */ callback.loadedURLSelf(o, this.url, err); +/* */ } +/* */ +/* 287 */ this.state = -1; +/* 288 */ return false; +/* */ } +/* */ +/* */ public Room getBackgroundLoadRoom() { +/* 292 */ return null; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\URLSelfLoader.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |