diff options
Diffstat (limited to 'NET/worlds/network/CacheFile.java')
| -rw-r--r-- | NET/worlds/network/CacheFile.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/NET/worlds/network/CacheFile.java b/NET/worlds/network/CacheFile.java new file mode 100644 index 0000000..abafa53 --- /dev/null +++ b/NET/worlds/network/CacheFile.java @@ -0,0 +1,91 @@ +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; + } +} |