2004/01/19 00:16:54
[org.ibex.core.git] / src / org / xwt / Stream.java
index 0d5f037..c28b070 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 //////////////////////////////////////////////////////////////////////////////
@@ -40,7 +45,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 +66,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); }