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=40fc71f88fc4486b22b953a1a6f4160726c2640f;hb=76b21655a0710caf4f972c107a3ab991032d7e10;hpb=b881f9415591b5069fe46a6ccc5d833cec816b65 diff --git a/src/org/ibex/core/Stream.java b/src/org/ibex/core/Stream.java index 40fc71f..83d4d1b 100644 --- a/src/org/ibex/core/Stream.java +++ b/src/org/ibex/core/Stream.java @@ -1,10 +1,14 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] -package org.ibex.js; +// 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.*; import java.util.zip.*; +import org.ibex.js.*; import org.ibex.util.*; -//import org.ibex.plat.*; +import org.ibex.plat.*; import org.ibex.net.*; /** @@ -13,7 +17,7 @@ import org.ibex.net.*; * 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 abstract class Stream extends JS.O implements JS.Cloneable { // Public Interface ////////////////////////////////////////////////////////////////////////////// @@ -23,9 +27,9 @@ public abstract class Stream extends 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; } @@ -38,11 +42,11 @@ 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; } + //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(); } + public InputStream getInputStream() throws IOException { return new org.ibex.net.HTTP(url).GET(null, null); } } /** byte arrays */ @@ -59,10 +63,12 @@ public abstract class Stream extends JS.Cloneable { public static class File extends Stream { private String path; public File(String path) { this.path = path; } - public String toString() { return "file:" + 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 */ @@ -76,7 +82,7 @@ public abstract class Stream extends 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); @@ -88,15 +94,17 @@ public abstract class Stream extends JS.Cloneable { } /** "unwrap" a Cab archive */ + /* public static class Cab extends Stream { private Stream parent; private String path; 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); } } + */ /** the Builtin resource */ public static class Builtin extends Stream { @@ -104,6 +112,14 @@ public abstract class Stream extends 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;