From fff819e5c802883cfa26df71a670f7df8e091400 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:39:51 +0000 Subject: [PATCH] 2003/10/20 01:41:22 darcs-hash:20040130073951-2ba56-335d7526c056c4b92be6c508462ed255927b2aa5.gz --- src/org/xwt/Res.java | 36 +++++++++++++------- src/org/xwt/builtin/splash.xwt | 73 ++++++++++++---------------------------- 2 files changed, 45 insertions(+), 64 deletions(-) diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index 896220b..4a8c7ed 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -21,8 +21,30 @@ public abstract class Res extends JS { public Res getParent() { return null; } + /** an InputStream that makes sure it is not in the MessageQueue when blocked on a read */ + private static class BackgroundInputStream extends FilterInputStream { + BackgroundInputStream(InputStream i) { super(i); } + private void suspend() throws IOException { + if (!ThreadMessage.suspendThread()) + throw new IOException("attempt to perform background-only operation in a foreground thread"); + } + private void resume() { + ThreadMessage.resumeThread(); + } + public int read() throws IOException { + suspend(); + try { return super.read(); } + finally { resume(); } + } + public int read(byte[] b, int off, int len) throws IOException { + suspend(); + try { return super.read(b, off, len); } + finally { resume(); } + } + } + /** returns an InputStream containing the Resource's contents */ - public InputStream getInputStream() throws IOException { return getInputStream(""); } + public final InputStream getInputStream() throws IOException { return new BackgroundInputStream(getInputStream("")); } public abstract InputStream getInputStream(String path) throws IOException; /** graft newResource in place of this resource on its parent */ @@ -100,16 +122,6 @@ public abstract class Res extends JS { return new FileInputStream((path + rest).replace('/', java.io.File.separatorChar)); } } - /** wrap a Res around a preexisting InputStream */ - public static class IS extends Res { - InputStream parent; - IS(InputStream parent) { this.parent = parent; } - public InputStream getInputStream(String path) { - if (!"".equals(path)) throw new JS.Exn("can't access subresources of IS"); - return parent; - } - } - /** "unwrap" a Zip archive */ public static class Zip extends Res { private Res parent; @@ -119,7 +131,7 @@ public abstract class Res extends JS { ZipInputStream zis = new ZipInputStream(parent.getInputStream()); ZipEntry ze = zis.getNextEntry(); while(ze != null && !ze.getName().equals(path)) ze = zis.getNextEntry(); - if (ze == null) throw new JS.Exn("requested file not found in archive"); + if (ze == null) throw new JS.Exn("requested file (" + path + ") not found in archive"); return zis; } } diff --git a/src/org/xwt/builtin/splash.xwt b/src/org/xwt/builtin/splash.xwt index dcbc66c..32ceb4c 100644 --- a/src/org/xwt/builtin/splash.xwt +++ b/src/org/xwt/builtin/splash.xwt @@ -1,66 +1,35 @@ -