X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fcore%2FStream.java;h=83d4d1ba3075426cf84604e63b65732f818bd8ef;hp=24f96c4530112d4406debb87dad5d94dbfea951e;hb=76b21655a0710caf4f972c107a3ab991032d7e10;hpb=ac84b5a03467c0853c7275105712ece6c71be1f1 diff --git a/src/org/ibex/core/Stream.java b/src/org/ibex/core/Stream.java index 24f96c4..83d4d1b 100644 --- a/src/org/ibex/core/Stream.java +++ b/src/org/ibex/core/Stream.java @@ -1,4 +1,7 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the GNU General Public License version 2 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.core; import java.io.*; @@ -24,9 +27,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); - 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; } @@ -41,7 +44,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; } - 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); } } @@ -63,7 +66,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 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 */ @@ -77,7 +82,7 @@ public abstract class Stream extends JS.O 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?JS.toString(key):path+'/'+JS.toString(key)); } public InputStream getInputStream() throws IOException { InputStream pis = parent.getInputStream(); ZipInputStream zis = new ZipInputStream(pis); @@ -96,7 +101,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 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); } } */ @@ -107,6 +112,14 @@ public abstract class Stream extends JS.O implements JS.Cloneable { public InputStream getInputStream() throws IOException { return Platform.getBuiltinInputStream(); } } + /** the Builtin resource */ + public static class FromInputStream extends Stream { + 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 is; } + } + /** shadow resource which replaces the graft */ public static class ProgressWatcher extends Stream { final Stream watchee;