changes made after tupshins reconstruction
[org.ibex.core.git] / src / org / xwt / Stream.java
index 0d5f037..3d847e8 100644 (file)
@@ -9,7 +9,12 @@ import org.xwt.util.*;
 import org.xwt.translators.MSPack;
 import org.bouncycastle.util.encoders.Base64;
 
-/** Base class for XWT resources */
+/**
+ *   Essentiall an InputStream "factory".  You can repeatedly ask a
+ *   Stream for an InputStream, and each InputStream you get back will
+ *   be totally independent of the others (ie separate stream position
+ *   and state) although they draw from the same data source.
+ */
 public abstract class Stream extends JS.Cloneable {
 
     // Public Interface //////////////////////////////////////////////////////////////////////////////
@@ -29,6 +34,7 @@ public abstract class Stream extends JS.Cloneable {
     /** HTTP or HTTPS resource */
     public static class HTTP extends Stream {
         private String url;
+        public String toString() { return "Stream.HTTP:" + url; }
         HTTP(String url) { while (url.endsWith("/")) url = url.substring(0, url.length() - 1); this.url = url; }
         public Object get(Object key) throws JSExn { return new HTTP(url + "/" + (String)key); }
         public String getCacheKey(Vec path) throws NotCacheableException { return url; }
@@ -40,7 +46,8 @@ public abstract class Stream extends JS.Cloneable {
         private byte[] bytes;
         private String cacheKey;
         ByteArray(byte[] bytes, String cacheKey) { this.bytes = bytes; this.cacheKey = cacheKey; }
-        public String getCacheKey() throws NotCacheableException { return cacheKey; }
+        public String getCacheKey() throws NotCacheableException {
+            if (cacheKey == null) throw new NotCacheableException(); return cacheKey; }
         public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(bytes); }
     }
 
@@ -60,9 +67,9 @@ public abstract class Stream extends JS.Cloneable {
         private String path;
         Zip(Stream parent) { this(parent, null); }
         Zip(Stream parent, String path) {
-            this.parent=parent;
-            while (path != null && path.startsWith("/")) path = path.substring(1);
-            this.path=path;
+            while(path != null && path.startsWith("/")) path = path.substring(1);
+            this.parent = parent;
+            this.path = path;
         }
         public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; }
         public Object get(Object key) throws JSExn { return new Zip(parent, path==null?(String)key:path+'/'+(String)key); }