summaryrefslogtreecommitdiff
path: root/NET/worlds/network/CacheFile.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/network/CacheFile.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/network/CacheFile.java')
-rw-r--r--NET/worlds/network/CacheFile.java91
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;
+ }
+}