package NET.worlds.network; import NET.worlds.console.Cursor; import java.util.Observer; public class CacheFile { private URL url; private CacheEntry entry; private boolean active; CacheFile(URL u, CacheEntry e) { this.url = u; this.active = true; this.entry = e; if (e != null) { e.incRef(); } } @Override public void finalize() { if (this.active) { this.active = false; if (this.entry != null) { this.entry.safeDecRef(); } } } public synchronized void close() { this.finalize(); } public synchronized void markTemporary() { if (this.entry != null) { this.entry.remoteTime = 0L; } } public boolean isActive() { return this.active; } public void callWhenLoaded(Observer o) { if (this.entry == null) { o.update(null, this.url); } else { this.entry.addObserver(o); } } public void waitUntilLoaded() { if (this.entry != null) { synchronized (this.entry) { Cursor c = Cursor.getActive(); if (c == null) { c = new Cursor(URL.make("system:WAIT_CURSOR")); c.activate(); } URL oldCursor = c.getURL(); c.setURL(URL.make("system:WAIT_CURSOR")); while (this.active && !this.done()) { try { this.entry.wait(); } catch (InterruptedException var5) { } } c.setURL(oldCursor); } } } public boolean error() { return this.entry == null ? false : this.entry.state == 5 || this.entry.state == 6; } public boolean done() { return this.entry == null ? true : this.entry.done(); } public String getLocalName() { return this.entry != null ? this.entry.localName : this.url.unalias(); } public int bytesLoaded() { return this.entry.bytes; } }