From 62a182913aaa769943df9c87a4640cf8933b443a Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:38:43 +0000 Subject: [PATCH] 2003/09/29 02:53:21 darcs-hash:20040130073843-2ba56-e8532798d8225ddcbb3f59d5f01aea2a6926e203.gz --- src/org/xwt/HTTP.java | 2 +- src/org/xwt/Res.java | 32 +++++++++----------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/org/xwt/HTTP.java b/src/org/xwt/HTTP.java index 38488e0..9ca8c6f 100644 --- a/src/org/xwt/HTTP.java +++ b/src/org/xwt/HTTP.java @@ -545,7 +545,7 @@ public class HTTP { } return ret; } finally { - if (!good) { this.HTTP.sock = null; this.HTTP.in = null; } + if (!good) { HTTP.this.sock = null; HTTP.this.in = null; } } } diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index 01856f2..10a920b 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -144,9 +144,9 @@ public abstract class Res extends JS { public static class ProgressWatcher extends Res { Res watchee; JS.Callable callback; - Graft(Res watchee, JS.Callable callback) { this.watchee = watchee; this.callback = callback; } + ProgressWatcher(Res watchee, JS.Callable callback) { this.watchee = watchee; this.callback = callback; } public InputStream getInputStream(String s) throws IOException { - return new FilterInputStream(graftee.getInputStream(s)) { + return new FilterInputStream(watchee.getInputStream(s)) { int bytesDownloaded = 0; public int read() throws IOException { int ret = super.read(); @@ -155,15 +155,18 @@ public abstract class Res extends JS { } 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) { + 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; } }; } - }); + } /** unpacks a Microsoft CAB file (possibly embedded in another file; we scan for 'MSCF' */ public static class CAB extends Res { @@ -173,28 +176,11 @@ public abstract class Res extends JS { return ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i & 0xff0000) >>> 8) | (i >>> 24); } public InputStream getInputStream(String path) throws IOException { - /* InputStream is = parent.getInputStream(); - byte[] scan = new byte[4]; - int ofs = 0; - for(int i=0; i<2; i++) { - // wierdly, .exe files have three MSCF's - while(scan[0] != 'M' || scan[1] != 'S' || scan[2] != 'C' || scan[3] != 'F') { - System.arraycopy(scan, 1, scan, 0, 3); - int read = is.read(); - if (read == -1) throw new JS.Exn("MSCF header tag not found in file"); - scan[3] = (byte)read; - ofs++; - } - scan[0] = 0; - } - Log.log(this, "found MSCF header at offset " + ofs); - return org.xwt.util.CAB.getFileInputStream(is, path, true); - */ try { - return org.xwt.util.CAB.getFileInputStream(is, 2, path); + return org.xwt.util.CAB.getFileInputStream(parent.getInputStream(), 2, path); } catch (EOFException eof) { throw new JS.Exn("MSCF header tag not found in file"); - } catch (EOFException eof) { + } catch (IOException ioe) { throw new JS.Exn("IOException while reading file"); } } -- 1.7.10.4