import java.util.zip.*;
import org.xwt.js.*;
import org.xwt.util.*;
+import org.bouncycastle.util.encoders.Base64;
/** base class for XWT resources */
public abstract class Res extends JS {
if (url.startsWith("https://")) return new HTTP(url);
if (url.startsWith("file:") && permitLocalFilesystem) return new File(url.substring(5));
if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
+ if (url.startsWith("data:")) return new ByteArray(Base64.decode(url.substring(5)));
+ if (url.startsWith("utf8:")) return new ByteArray(url.substring(5).getBytes());
throw new JS.Exn("invalid resource specifier " + url);
}
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;
return ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i & 0xff0000) >>> 8) | (i >>> 24);
}
public InputStream getInputStream(String path) throws IOException {
- InputStream is = parent.getInputStream();
+ /* InputStream is = parent.getInputStream();
byte[] scan = new byte[4];
int ofs = 0;
for(int i=0; i<2; i++) {
}
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);
+ } catch (EOFException eof) {
+ throw new JS.Exn("MSCF header tag not found in file");
+ } catch (EOFException eof) {
+ throw new JS.Exn("IOException while reading file");
+ }
}
}