fixed up Stream for new JS API
authoradam <adam@megacz.com>
Wed, 29 Dec 2004 02:47:13 +0000 (02:47 +0000)
committeradam <adam@megacz.com>
Wed, 29 Dec 2004 02:47:13 +0000 (02:47 +0000)
darcs-hash:20041229024713-5007d-5b84cb7a85f496d2d1398bee0d905fba266316cb.gz

src/org/ibex/core/Stream.java

index 24f96c4..60afa46 100644 (file)
@@ -24,9 +24,9 @@ public abstract class Stream extends JS.O implements JS.Cloneable {
     // streams are "sealed" by default to prevent accidental object leakage
     public void put(Object key, Object val) { }
     private Cache getCache = new Cache(100);
     // streams are "sealed" by default to prevent accidental object leakage
     public void put(Object key, Object val) { }
     private Cache getCache = new Cache(100);
-    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;
     }
         if (ret == null) getCache.put(key, ret = _get(key));
         return ret;
     }
@@ -41,7 +41,7 @@ public abstract class Stream extends JS.O implements JS.Cloneable {
         private String url;
         //public String toString() { return "Stream.HTTP:" + url; }
         public HTTP(String url) { while (url.endsWith("/")) url = url.substring(0, url.length() - 1); this.url = url; }
         private String url;
         //public String toString() { return "Stream.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 JS _get(JS key) throws JSExn { return new HTTP(url + "/" + JS.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); }
     }
         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 +63,9 @@ public abstract class Stream extends JS.O 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 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 {
+            System.out.println("get: " + JS.debugToString(key));
+            return new File(path + java.io.File.separatorChar + JS.toString(key)); }
     }
 
     /** "unwrap" a Zip archive */
     }
 
     /** "unwrap" a Zip archive */
@@ -77,7 +79,7 @@ public abstract class Stream extends JS.O implements JS.Cloneable {
             this.path = path;
         }
         public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; }
             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?JS.toString(key):path+'/'+JS.toString(key)); }
         public InputStream getInputStream() throws IOException {
             InputStream pis = parent.getInputStream();
             ZipInputStream zis = new ZipInputStream(pis);
         public InputStream getInputStream() throws IOException {
             InputStream pis = parent.getInputStream();
             ZipInputStream zis = new ZipInputStream(pis);
@@ -96,7 +98,7 @@ public abstract class Stream extends JS.O implements JS.Cloneable {
         public Cab(Stream parent) { this(parent, null); }
         public Cab(Stream parent, String path) { this.parent = parent; this.path = path; }
         public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!cab:"; }
         public Cab(Stream parent) { this(parent, null); }
         public Cab(Stream 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); }
     }
     */
         public InputStream getInputStream() throws IOException { return new MSPack(parent.getInputStream()).getInputStream(path); }
     }
     */