projects
/
org.ibex.core.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a337940
)
cache Stream objects to make
author
adam
<adam@megacz.com>
Wed, 7 Apr 2004 20:35:36 +0000
(20:35 +0000)
committer
adam
<adam@megacz.com>
Wed, 7 Apr 2004 20:35:36 +0000
(20:35 +0000)
darcs-hash:
20040407203536
-5007d-
daf21e5cea6a62f1a949d9b0bada2924cb1f2fd4
.gz
src/org/ibex/Stream.java
patch
|
blob
|
history
diff --git
a/src/org/ibex/Stream.java
b/src/org/ibex/Stream.java
index
a7a3bb8
..
ef63fe5
100644
(file)
--- a/
src/org/ibex/Stream.java
+++ b/
src/org/ibex/Stream.java
@@
-22,7
+22,13
@@
public abstract class Stream extends JS.Cloneable {
// streams are "sealed" by default to prevent accidental object leakage
public void put(Object key, Object val) throws JSExn { }
// streams are "sealed" by default to prevent accidental object leakage
public void put(Object key, Object val) throws JSExn { }
- public Object get(Object key) throws JSExn { return null; }
+ private Cache getCache = new Cache(100);
+ protected Object _get(Object key) throws JSExn { return null; }
+ public final Object get(Object key) throws JSExn {
+ Object ret = getCache.get(key);
+ if (ret == null) getCache.put(key, ret = _get(key));
+ return ret;
+ }
// Private Interface //////////////////////////////////////////////////////////////////////////////
// Private Interface //////////////////////////////////////////////////////////////////////////////
@@
-34,7
+40,7
@@
public abstract class Stream extends JS.Cloneable {
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; }
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 Object _get(Object key) throws JSExn { return new HTTP(url + "/" + (String)key); }
public String getCacheKey(Vec path) throws NotCacheableException { return url; }
public InputStream getInputStream() throws IOException { return new org.ibex.HTTP(url).GET(); }
}
public String getCacheKey(Vec path) throws NotCacheableException { return url; }
public InputStream getInputStream() throws IOException { return new org.ibex.HTTP(url).GET(); }
}
@@
-56,7
+62,7
@@
public abstract class Stream extends 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 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) throws JSExn { return new File(path + java.io.File.separatorChar + (String)key); }
+ public Object _get(Object key) throws JSExn { return new File(path + java.io.File.separatorChar + (String)key); }
}
/** "unwrap" a Zip archive */
}
/** "unwrap" a Zip archive */
@@
-70,7
+76,7
@@
public abstract class Stream extends JS.Cloneable {
this.path = path;
}
public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; }
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); }
+ public Object _get(Object key) throws JSExn { return new Zip(parent, path==null?(String)key:path+'/'+(String)key); }
public InputStream getInputStream() throws IOException {
InputStream pis = parent.getInputStream();
ZipInputStream zis = new ZipInputStream(pis);
public InputStream getInputStream() throws IOException {
InputStream pis = parent.getInputStream();
ZipInputStream zis = new ZipInputStream(pis);
@@
-88,7
+94,7
@@
public abstract class Stream extends JS.Cloneable {
Cab(Stream parent) { this(parent, null); }
Cab(Stream parent, String path) { this.parent = parent; this.path = path; }
public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!cab:"; }
Cab(Stream parent) { this(parent, null); }
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) throws JSExn { return new Cab(parent, path==null?(String)key:path+'/'+(String)key); }
+ public Object _get(Object 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); }
}
public InputStream getInputStream() throws IOException { return new MSPack(parent.getInputStream()).getInputStream(path); }
}