From ffb9735ec64193f5a6ef0368bd244f9fac0e1c09 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 16 Jan 2005 05:16:59 +0000 Subject: [PATCH] HashMap->Hash, update Fountain, remove external dependencies darcs-hash:20050116051659-5007d-c187ab3ad76b0a59c5434f5c8427a336523e12c6.gz --- src/org/ibex/js/Fountain.java | 57 ++++++++++++++++++++++------------------- src/org/ibex/js/JS.java | 2 +- src/org/ibex/js/XMLRPC.java | 2 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/org/ibex/js/Fountain.java b/src/org/ibex/js/Fountain.java index f1bf14b..e78b58b 100644 --- a/src/org/ibex/js/Fountain.java +++ b/src/org/ibex/js/Fountain.java @@ -6,6 +6,7 @@ package org.ibex.js; import java.io.*; import java.util.zip.*; +import org.ibex.js.*; import org.ibex.util.*; import org.ibex.net.*; @@ -15,7 +16,7 @@ import org.ibex.net.*; * be totally independent of the others (ie separate stream position * and state) although they draw from the same data source. */ -public abstract class Fountain extends JS.Immutable implements JS.Cloneable { +public abstract class Fountain extends JS.Obj implements JS.Cloneable { // Public Interface ////////////////////////////////////////////////////////////////////////////// @@ -24,9 +25,9 @@ public abstract class Fountain extends JS.Immutable implements JS.Cloneable { // streams are "sealed" by default to prevent accidental object leakage private Cache getCache = new Cache(100, true); - protected Object _get(Object key) { return null; } - public final Object get(Object key) { - Object ret = getCache.get(key); + protected JS _get(JS key) throws JSExn { return null; } + public final JS get(JS key) throws JSExn { + JS ret = (JS)getCache.get(key); if (ret == null) getCache.put(key, ret = _get(key)); return ret; } @@ -39,10 +40,10 @@ public abstract class Fountain extends JS.Immutable implements JS.Cloneable { /** HTTP or HTTPS resource */ public static class HTTP extends Fountain { private String url; - //public String toString() { return "Stream.HTTP:" + url; } + //public String toString() { return "Fountain.HTTP:" + url; } public HTTP(String url) { while (url.endsWith("/")) url = url.substring(0, url.length() - 1); this.url = url; } - public Object _get(Object key) { return new HTTP(url + "/" + (String)key); } - public String getCacheKey(Basket.List path) throws NotCacheableException { return url; } + public JS _get(JS key) throws JSExn { return new HTTP(url + "/" + JSU.toString(key)); } + public String getCacheKey(Vec path) throws NotCacheableException { return url; } public InputStream getInputStream() throws IOException { return new org.ibex.net.HTTP(url).GET(null, null); } } @@ -63,7 +64,7 @@ public abstract class Fountain extends JS.Immutable implements JS.Cloneable { //public String toString() { return "file:" + path; } public String getCacheKey() throws NotCacheableException { throw new NotCacheableException(); /* already on disk */ } public InputStream getInputStream() throws IOException { return new FileInputStream(path); } - public Object _get(Object key) { return new File(path + java.io.File.separatorChar + (String)key); } + public JS _get(JS key) throws JSExn { return new File(path + java.io.File.separatorChar + JSU.toString(key)); } } /** "unwrap" a Zip archive */ @@ -77,7 +78,7 @@ public abstract class Fountain extends JS.Immutable implements JS.Cloneable { this.path = path; } public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; } - public Object _get(Object key) { return new Zip(parent, path==null?(String)key:path+'/'+(String)key); } + public JS _get(JS key) throws JSExn { return new Zip(parent, path==null?JSU.toString(key):path+'/'+JSU.toString(key)); } public InputStream getInputStream() throws IOException { InputStream pis = parent.getInputStream(); ZipInputStream zis = new ZipInputStream(pis); @@ -89,32 +90,31 @@ public abstract class Fountain extends JS.Immutable implements JS.Cloneable { } /** "unwrap" a Cab archive */ - /* temporarily disabled due to dependency issues + /* public static class Cab extends Fountain { private Fountain parent; private String path; public Cab(Fountain parent) { this(parent, null); } public Cab(Fountain parent, String path) { this.parent = parent; this.path = path; } public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!cab:"; } - public Object _get(Object key) { return new Cab(parent, path==null?(String)key:path+'/'+(String)key); } + public JS _get(JS key) throws JSExn { return new Cab(parent, path==null?(String)key:path+'/'+(String)key); } public InputStream getInputStream() throws IOException { return new MSPack(parent.getInputStream()).getInputStream(path); } } */ - /** the Builtin resource */ - /* temporarily disabled due to dependency issues - public static class Builtin extends Fountain { + public static class FromInputStream extends Fountain { + private final InputStream is; + public FromInputStream(InputStream is) { this.is = is; } public String getCacheKey() throws NotCacheableException { throw new NotCacheableException(); } - public InputStream getInputStream() throws IOException { return Platform.getBuiltinInputStream(); } + public InputStream getInputStream() throws IOException { return is; } } - */ /** shadow resource which replaces the graft */ - /* temporarily disabled due to dependency issues public static class ProgressWatcher extends Fountain { + private final JS[] callargs = new JS[2]; final Fountain watchee; - JS callback; - public ProgressWatcher(Fountain watchee, JS callback) { this.watchee = watchee; this.callback = callback; } + Callable callback; + public ProgressWatcher(Fountain watchee, Callable callback) { this.watchee = watchee; this.callback = callback; } public String getCacheKey() throws NotCacheableException { return watchee.getCacheKey(); } public InputStream getInputStream() throws IOException { final InputStream is = watchee.getInputStream(); @@ -128,26 +128,29 @@ public abstract class Fountain extends JS.Immutable implements JS.Cloneable { public int read(byte[] b, int off, int len) throws IOException { int ret = super.read(b, off, len); if (ret != 1) bytesDownloaded += ret; - Scheduler.add(new Task() { public void perform() throws IOException, JSExn { - callback.call(N(bytesDownloaded), - N(is instanceof KnownLength ? ((KnownLength)is).getLength() : 0), null, null, 2); - } }); + callargs[0] = JSU.N(bytesDownloaded); + callargs[1] = JSU.N(is instanceof KnownLength.KnownLengthInputStream ? + ((KnownLength.KnownLengthInputStream)is).getLength() : 0); + try { + callback.run(callargs); + } catch (Exception e) { + Log.warn(ProgressWatcher.class, e); + } return ret; } }; } } - */ /** subclass from this if you want a CachedInputStream for each path */ - /* temporarily disabled due to dependency issues - public static class CachedStream extends Fountain { + /* + public static class CachedFountain extends Fountain { private Fountain parent; private boolean disk = false; private String key; public String getCacheKey() throws NotCacheableException { return key; } CachedInputStream cis = null; - public CachedStream(Fountain p, String s, boolean d) throws NotCacheableException { + public CachedFountain(Fountain p, String s, boolean d) throws NotCacheableException { this.parent = p; this.disk = d; this.key = p.getCacheKey(); } public InputStream getInputStream() throws IOException { diff --git a/src/org/ibex/js/JS.java b/src/org/ibex/js/JS.java index 75a34e0..1617511 100644 --- a/src/org/ibex/js/JS.java +++ b/src/org/ibex/js/JS.java @@ -116,7 +116,7 @@ public interface JS { public String coerceToString() throws JSExn { return clonee.coerceToString(); } } - public static class Obj extends Basket.HashMap implements JS { + public static class Obj extends Basket.Hash implements JS { private static final String[] emptystr = new String[0]; private static final Placeholder holder = new Placeholder(); diff --git a/src/org/ibex/js/XMLRPC.java b/src/org/ibex/js/XMLRPC.java index cdf4789..cc52aa6 100644 --- a/src/org/ibex/js/XMLRPC.java +++ b/src/org/ibex/js/XMLRPC.java @@ -330,7 +330,7 @@ public class XMLRPC extends JS.Immutable { final Object call(final Pausable callback, final JSArray args) { try { if (Log.rpc) Log.info(this, "call to " + url + " : " + method); - if (tracker == null) tracker = new Basket.HashMap(); + if (tracker == null) tracker = new Basket.Hash(); if (objects == null) objects = new Basket.Array(); String request = buildRequest(args); if (Log.rpc) Log.info(this, "send:\n" + request); -- 1.7.10.4