+ public int hashCode() { return graftee.hashCode(); }
+ public InputStream getInputStream(String s) throws IOException { return graftee.getInputStream(s); }
+ public Object get(Object key) { return replaced_key.equals(key) ? replaced_val : graftee.get(key); }
+ public String getDescriptiveName() { return graftee.getDescriptiveName(); }
+ public Res getParent() { return graftee.getParent(); }
+ }
+
+ /** shadow resource which replaces the graft */
+ public static class ProgressWatcher extends Res {
+ Res watchee;
+ JS.Callable callback;
+ ProgressWatcher(Res watchee, JS.Callable callback) { this.watchee = watchee; this.callback = callback; }
+ public InputStream getInputStream(String s) throws IOException {
+ return new FilterInputStream(watchee.getInputStream(s)) {
+ int bytesDownloaded = 0;
+ public int read() throws IOException {
+ int ret = super.read();
+ if (ret != -1) bytesDownloaded++;
+ return ret;
+ }
+ public int read(byte[] b, int off, int len) throws IOException {
+ int ret = super.read(b, off, len);
+ if (ret != 1) bytesDownloaded += ret;
+ ThreadMessage.newthread(new JS.Callable() { public Object call(JS.Array a) {
+ JS.Array args = new JS.Array();
+ args.addElement(new Integer(bytesDownloaded));
+ callback.call(args);
+ return null;
+ } });
+ return ret;
+ }
+ };