From d742dcc262d6af132f1c31d343010ee7a5af25e9 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:38:40 +0000 Subject: [PATCH] 2003/09/28 22:05:58 darcs-hash:20040130073840-2ba56-7b510046272e4bd532df2a9a01346864c01a66de.gz --- src/org/xwt/Res.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index 107c766..862b12d 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -140,6 +140,31 @@ public abstract class Res extends JS { public Res getParent() { return graftee.getParent(); } } + /** shadow resource which replaces the graft */ + public static class ProgressWatcher extends Res { + Res watchee; + JS.Callable callback; + Graft(Res watchee, JS.Callable callback) { this.watchee = watchee; this.callback = callback; } + public InputStream getInputStream(String s) throws IOException { + return new FilterInputStream(graftee.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); + ThreadMessage.newthread(new JS.Callable() { public Object call(JS.Args a) { + JS.Array args = new JS.Array(); + args.addElement(new Integer(bytesDownloaded)); + callback.call(args); + } }); + } + }; + } + }); + /** unpacks a Microsoft CAB file (possibly embedded in another file; we scan for 'MSCF' */ public static class CAB extends Res { private Res parent; -- 1.7.10.4