2003/12/29 22:29:30
[org.ibex.core.git] / src / org / xwt / Stream.java
similarity index 84%
rename from src/org/xwt/Res.java
rename to src/org/xwt/Stream.java
index b529a4e..8300478 100644 (file)
@@ -11,14 +11,14 @@ import org.bouncycastle.util.encoders.Base64;
 
 
 /** Base class for XWT resources */
-public abstract class Res extends JS {
+public abstract class Stream extends JS {
 
     /** return a resource for a given url */
-    public static final Res fromURL(String url) throws JSExn {
-        if (url.startsWith("http://")) return new Res.HTTP(url);
-        else if (url.startsWith("https://")) return new Res.HTTP(url);
-        else if (url.startsWith("data:")) return new Res.ByteArray(Base64.decode(url.substring(5)), null);
-        else if (url.startsWith("utf8:")) return new Res.ByteArray(url.substring(5).getBytes(), null);
+    public static final Stream fromURL(String url) throws JSExn {
+        if (url.startsWith("http://")) return new Stream.HTTP(url);
+        else if (url.startsWith("https://")) return new Stream.HTTP(url);
+        else if (url.startsWith("data:")) return new Stream.ByteArray(Base64.decode(url.substring(5)), null);
+        else if (url.startsWith("utf8:")) return new Stream.ByteArray(url.substring(5).getBytes(), null);
         throw new JSExn("invalid resource specifier " + url);
     }
 
@@ -34,7 +34,7 @@ public abstract class Res extends JS {
     public final InputStream getInputStream() throws IOException { return getInputStream(""); }
     public abstract InputStream getInputStream(String path) throws IOException;
 
-    public Res addExtension(String extension) { return new Ref(this, extension); }
+    public Stream addExtension(String extension) { return new Ref(this, extension); }
 
     public Object get(Object key) throws JSExn {
         if ("".equals(key)) {
@@ -65,14 +65,14 @@ public abstract class Res extends JS {
     public String getCacheKey() throws NotCacheableException { throw notCacheable; }
 
     /** subclass from this if you want a CachedInputStream for each path */
-    public static class CachedRes extends Res {
-        private Res parent;
+    public static class CachedStream extends Stream {
+        private Stream parent;
         private boolean disk = false;
         private String key;
         public String getCacheKey() throws NotCacheableException { return key; }
         public String toString() { return key; }
         private Hash cachedInputStreams = new Hash();
-        public CachedRes(Res p, String s, boolean d) throws NotCacheableException {
+        public CachedStream(Stream p, String s, boolean d) throws NotCacheableException {
             this.parent = p; this.disk = d; this.key = p.getCacheKey();
         }
         public InputStream getInputStream(String path) throws IOException {
@@ -95,7 +95,7 @@ public abstract class Res extends JS {
     // Useful Subclasses //////////////////////////////////////////////////////////////////////
 
     /** HTTP or HTTPS resource */
-    public static class HTTP extends Res {
+    public static class HTTP extends Stream {
         private String url;
         HTTP(String url) { while (url.endsWith("/")) url = url.substring(0, url.length() - 1); this.url = url; }
         public String toString() { return url; }
@@ -104,7 +104,7 @@ public abstract class Res extends JS {
     }
 
     /** byte arrays */
-    public static class ByteArray extends Res {
+    public static class ByteArray extends Stream {
         private byte[] bytes;
         private String cacheKey = null;
         ByteArray(byte[] bytes, String cacheKey) { this.bytes = bytes; this.cacheKey = cacheKey; }
@@ -117,7 +117,7 @@ public abstract class Res extends JS {
     }
 
     /** a file */
-    public static class File extends Res {
+    public static class File extends Stream {
         private String path;
         File(String path) {
             while (path.endsWith(java.io.File.separatorChar + "")) path = path.substring(0, path.length() - 1);
@@ -130,9 +130,9 @@ public abstract class Res extends JS {
     }
 
     /** "unwrap" a Zip archive */
-    public static class Zip extends Res {
-        private Res parent;
-        Zip(Res parent) { this.parent = parent; }
+    public static class Zip extends Stream {
+        private Stream parent;
+        Zip(Stream parent) { this.parent = parent; }
         public String toString() { return parent.toString() + "!zip"; }
         public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; }
         public InputStream getInputStream(String path) throws IOException {
@@ -147,9 +147,9 @@ public abstract class Res extends JS {
     }
 
     /** "unwrap" a Cab archive */
-    public static class Cab extends Res {
-        private Res parent;
-        Cab(Res parent) { this.parent = parent; }
+    public static class Cab extends Stream {
+        private Stream parent;
+        Cab(Stream parent) { this.parent = parent; }
         public String toString() { return parent.toString() + "!cab"; }
         public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!cab:"; }
         public InputStream getInputStream(String path) throws IOException {
@@ -159,7 +159,7 @@ public abstract class Res extends JS {
     }
 
     /** the Builtin resource */
-    public static class Builtin extends Res {
+    public static class Builtin extends Stream {
         public Builtin() { };
         public String getCacheKey() throws NotCacheableException { throw notCacheable; }    // not cacheable
         public String toString() { return "builtin:"; }
@@ -170,22 +170,22 @@ public abstract class Res extends JS {
     }
 
     /** what you get when you reference a subresource */
-    public static class Ref extends Res {
-        Res parent;
+    public static class Ref extends Stream {
+        Stream parent;
         Object key;
         public String toString() { return parent.toString() + "/" + key; }
-        Ref(Res parent, Object key) { this.parent = parent; this.key = key; }
+        Ref(Stream parent, Object key) { this.parent = parent; this.key = key; }
         public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "/" + key; }
-        public Res addExtension(String extension) {
+        public Stream addExtension(String extension) {
             return ((String)key).endsWith(extension) ? this : new Ref(parent, key + extension); }
         public InputStream getInputStream(String path) throws IOException { return parent.getInputStream("/" + key + path); }
     }
 
     /** provides redirection of a specified key */
-    public static class Graft extends Res {
-        Res graftee;
+    public static class Graft extends Stream {
+        Stream graftee;
         Object replaced_key, replaced_val;
-        Graft(Res graftee, Object key, Object val) { this.graftee = graftee; this.replaced_key = key; this.replaced_val = val; }
+        Graft(Stream graftee, Object key, Object val) { this.graftee = graftee; this.replaced_key = key; this.replaced_val = val; }
         public boolean equals(Object o) { return this == o || graftee.equals(o); }
         public int hashCode() { return graftee.hashCode(); }
         public InputStream getInputStream(String s) throws IOException { return graftee.getInputStream(s); }
@@ -205,10 +205,10 @@ public abstract class Res extends JS {
     }
 
     /** shadow resource which replaces the graft */
-    public static class ProgressWatcher extends Res {
-        final Res watchee;
+    public static class ProgressWatcher extends Stream {
+        final Stream watchee;
         JSFunction callback;
-        ProgressWatcher(Res watchee, JSFunction callback) { this.watchee = watchee; this.callback = callback; }
+        ProgressWatcher(Stream watchee, JSFunction callback) { this.watchee = watchee; this.callback = callback; }
         public String toString() { return watchee.toString(); }
         public String getCacheKey() throws NotCacheableException { return watchee.getCacheKey(); }
         public InputStream getInputStream(String s) throws IOException {