X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2FJU%2FOC.js;h=0764b7ad903edd64edd5e577d78fc378f6be5c94;hp=ce631ff6befbb51a84bc488868140f1e255f4946;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/JU/OC.js b/site/j2s/JU/OC.js index ce631ff..0764b7a 100644 --- a/site/j2s/JU/OC.js +++ b/site/j2s/JU/OC.js @@ -1,232 +1,232 @@ -Clazz.declarePackage ("JU"); -Clazz.load (["java.io.OutputStream"], "JU.OC", ["java.io.BufferedWriter", "$.ByteArrayOutputStream", "$.OutputStreamWriter", "JU.Base64", "$.SB"], function () { -c$ = Clazz.decorateAsClass (function () { -this.bytePoster = null; -this.fileName = null; -this.bw = null; -this.isLocalFile = false; -this.byteCount = 0; -this.isCanceled = false; -this.closed = false; -this.os = null; -this.sb = null; -this.type = null; -this.$isBase64 = false; -this.os0 = null; -this.bytes = null; -Clazz.instantialize (this, arguments); -}, JU, "OC", java.io.OutputStream); -Clazz.defineMethod (c$, "setParams", -function (bytePoster, fileName, asWriter, os) { -this.bytePoster = bytePoster; -this.fileName = fileName; -this.$isBase64 = ";base64,".equals (fileName); -if (this.$isBase64) { -fileName = null; -this.os0 = os; -os = null; -}this.os = os; -this.isLocalFile = (fileName != null && !JU.OC.isRemote (fileName)); -if (asWriter && !this.$isBase64 && os != null) this.bw = new java.io.BufferedWriter ( new java.io.OutputStreamWriter (os)); -return this; -}, "javajs.api.BytePoster,~S,~B,java.io.OutputStream"); -Clazz.defineMethod (c$, "setBytes", -function (b) { -this.bytes = b; -return this; -}, "~A"); -Clazz.defineMethod (c$, "getFileName", -function () { -return this.fileName; -}); -Clazz.defineMethod (c$, "getName", -function () { -return (this.fileName == null ? null : this.fileName.substring (this.fileName.lastIndexOf ("/") + 1)); -}); -Clazz.defineMethod (c$, "getByteCount", -function () { -return this.byteCount; -}); -Clazz.defineMethod (c$, "setType", -function (type) { -this.type = type; -}, "~S"); -Clazz.defineMethod (c$, "getType", -function () { -return this.type; -}); -Clazz.defineMethod (c$, "append", -function (s) { -try { -if (this.bw != null) { -this.bw.write (s); -} else if (this.os == null) { -if (this.sb == null) this.sb = new JU.SB (); -this.sb.append (s); -} else { -var b = s.getBytes (); -this.os.write (b, 0, b.length); -this.byteCount += b.length; -return this; -}} catch (e) { -if (Clazz.exceptionOf (e, java.io.IOException)) { -} else { -throw e; -} -} -this.byteCount += s.length; -return this; -}, "~S"); -Clazz.defineMethod (c$, "reset", -function () { -this.sb = null; -this.initOS (); -}); -Clazz.defineMethod (c$, "initOS", - function () { -if (this.sb != null) { -var s = this.sb.toString (); -this.reset (); -this.append (s); -return; -}try { -{ -this.os = null; -}if (this.os == null) this.os = new java.io.ByteArrayOutputStream (); -if (this.bw != null) { -this.bw.close (); -this.bw = new java.io.BufferedWriter ( new java.io.OutputStreamWriter (this.os)); -}} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -System.out.println (e.toString ()); -} else { -throw e; -} -} -this.byteCount = 0; -}); -Clazz.overrideMethod (c$, "write", -function (buf, i, len) { -if (this.os == null) this.initOS (); -try { -this.os.write (buf, i, len); -} catch (e) { -if (Clazz.exceptionOf (e, java.io.IOException)) { -} else { -throw e; -} -} -this.byteCount += len; -}, "~A,~N,~N"); -Clazz.overrideMethod (c$, "writeByteAsInt", -function (b) { -if (this.os == null) this.initOS (); -{ -this.os.writeByteAsInt(b); -}this.byteCount++; -}, "~N"); -Clazz.defineMethod (c$, "cancel", -function () { -this.isCanceled = true; -this.closeChannel (); -}); -Clazz.defineMethod (c$, "closeChannel", -function () { -if (this.closed) return null; -try { -if (this.bw != null) { -this.bw.flush (); -this.bw.close (); -} else if (this.os != null) { -this.os.flush (); -this.os.close (); -}if (this.os0 != null && this.isCanceled) { -this.os0.flush (); -this.os0.close (); -}} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -} else { -throw e; -} -} -if (this.isCanceled) { -this.closed = true; -return null; -}if (this.fileName == null) { -if (this.$isBase64) { -var s = this.getBase64 (); -if (this.os0 != null) { -this.os = this.os0; -this.append (s); -}this.sb = new JU.SB (); -this.sb.append (s); -this.$isBase64 = false; -return this.closeChannel (); -}return (this.sb == null ? null : this.sb.toString ()); -}this.closed = true; -{ -var data = (this.sb == null ? this.toByteArray() : -this.sb.toString()); if (typeof this.fileName == "function") { -this.fileName(data); } else { Jmol._doAjax(this.fileName, -null, data); } -}return null; -}); -Clazz.defineMethod (c$, "isBase64", -function () { -return this.$isBase64; -}); -Clazz.defineMethod (c$, "getBase64", -function () { -return JU.Base64.getBase64 (this.toByteArray ()).toString (); -}); -Clazz.defineMethod (c$, "toByteArray", -function () { -return (this.bytes != null ? this.bytes : Clazz.instanceOf (this.os, java.io.ByteArrayOutputStream) ? (this.os).toByteArray () : null); -}); -Clazz.defineMethod (c$, "close", -function () { -this.closeChannel (); -}); -Clazz.overrideMethod (c$, "toString", -function () { -if (this.bw != null) try { -this.bw.flush (); -} catch (e) { -if (Clazz.exceptionOf (e, java.io.IOException)) { -} else { -throw e; -} -} -if (this.sb != null) return this.closeChannel (); -return this.byteCount + " bytes"; -}); -Clazz.defineMethod (c$, "postByteArray", - function () { -var bytes = (this.sb == null ? this.toByteArray () : this.sb.toString ().getBytes ()); -return this.bytePoster.postByteArray (this.fileName, bytes); -}); -c$.isRemote = Clazz.defineMethod (c$, "isRemote", -function (fileName) { -if (fileName == null) return false; -var itype = JU.OC.urlTypeIndex (fileName); -return (itype >= 0 && itype != 4); -}, "~S"); -c$.isLocal = Clazz.defineMethod (c$, "isLocal", -function (fileName) { -if (fileName == null) return false; -var itype = JU.OC.urlTypeIndex (fileName); -return (itype < 0 || itype == 4); -}, "~S"); -c$.urlTypeIndex = Clazz.defineMethod (c$, "urlTypeIndex", -function (name) { -if (name == null) return -2; -for (var i = 0; i < JU.OC.urlPrefixes.length; ++i) { -if (name.startsWith (JU.OC.urlPrefixes[i])) { -return i; -}} -return -1; -}, "~S"); -Clazz.defineStatics (c$, -"urlPrefixes", Clazz.newArray (-1, ["http:", "https:", "sftp:", "ftp:", "file:"]), -"URL_LOCAL", 4); -}); +Clazz.declarePackage ("JU"); +Clazz.load (["java.io.OutputStream"], "JU.OC", ["java.io.BufferedWriter", "$.ByteArrayOutputStream", "$.OutputStreamWriter", "JU.Base64", "$.SB"], function () { +c$ = Clazz.decorateAsClass (function () { +this.bytePoster = null; +this.fileName = null; +this.bw = null; +this.isLocalFile = false; +this.byteCount = 0; +this.isCanceled = false; +this.closed = false; +this.os = null; +this.sb = null; +this.type = null; +this.$isBase64 = false; +this.os0 = null; +this.bytes = null; +Clazz.instantialize (this, arguments); +}, JU, "OC", java.io.OutputStream); +Clazz.defineMethod (c$, "setParams", +function (bytePoster, fileName, asWriter, os) { +this.bytePoster = bytePoster; +this.fileName = fileName; +this.$isBase64 = ";base64,".equals (fileName); +if (this.$isBase64) { +fileName = null; +this.os0 = os; +os = null; +}this.os = os; +this.isLocalFile = (fileName != null && !JU.OC.isRemote (fileName)); +if (asWriter && !this.$isBase64 && os != null) this.bw = new java.io.BufferedWriter ( new java.io.OutputStreamWriter (os)); +return this; +}, "javajs.api.BytePoster,~S,~B,java.io.OutputStream"); +Clazz.defineMethod (c$, "setBytes", +function (b) { +this.bytes = b; +return this; +}, "~A"); +Clazz.defineMethod (c$, "getFileName", +function () { +return this.fileName; +}); +Clazz.defineMethod (c$, "getName", +function () { +return (this.fileName == null ? null : this.fileName.substring (this.fileName.lastIndexOf ("/") + 1)); +}); +Clazz.defineMethod (c$, "getByteCount", +function () { +return this.byteCount; +}); +Clazz.defineMethod (c$, "setType", +function (type) { +this.type = type; +}, "~S"); +Clazz.defineMethod (c$, "getType", +function () { +return this.type; +}); +Clazz.defineMethod (c$, "append", +function (s) { +try { +if (this.bw != null) { +this.bw.write (s); +} else if (this.os == null) { +if (this.sb == null) this.sb = new JU.SB (); +this.sb.append (s); +} else { +var b = s.getBytes (); +this.os.write (b, 0, b.length); +this.byteCount += b.length; +return this; +}} catch (e) { +if (Clazz.exceptionOf (e, java.io.IOException)) { +} else { +throw e; +} +} +this.byteCount += s.length; +return this; +}, "~S"); +Clazz.defineMethod (c$, "reset", +function () { +this.sb = null; +this.initOS (); +}); +Clazz.defineMethod (c$, "initOS", + function () { +if (this.sb != null) { +var s = this.sb.toString (); +this.reset (); +this.append (s); +return; +}try { +{ +this.os = null; +}if (this.os == null) this.os = new java.io.ByteArrayOutputStream (); +if (this.bw != null) { +this.bw.close (); +this.bw = new java.io.BufferedWriter ( new java.io.OutputStreamWriter (this.os)); +}} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +System.out.println (e.toString ()); +} else { +throw e; +} +} +this.byteCount = 0; +}); +Clazz.overrideMethod (c$, "write", +function (buf, i, len) { +if (this.os == null) this.initOS (); +try { +this.os.write (buf, i, len); +} catch (e) { +if (Clazz.exceptionOf (e, java.io.IOException)) { +} else { +throw e; +} +} +this.byteCount += len; +}, "~A,~N,~N"); +Clazz.overrideMethod (c$, "writeByteAsInt", +function (b) { +if (this.os == null) this.initOS (); +{ +this.os.writeByteAsInt(b); +}this.byteCount++; +}, "~N"); +Clazz.defineMethod (c$, "cancel", +function () { +this.isCanceled = true; +this.closeChannel (); +}); +Clazz.defineMethod (c$, "closeChannel", +function () { +if (this.closed) return null; +try { +if (this.bw != null) { +this.bw.flush (); +this.bw.close (); +} else if (this.os != null) { +this.os.flush (); +this.os.close (); +}if (this.os0 != null && this.isCanceled) { +this.os0.flush (); +this.os0.close (); +}} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +} else { +throw e; +} +} +if (this.isCanceled) { +this.closed = true; +return null; +}if (this.fileName == null) { +if (this.$isBase64) { +var s = this.getBase64 (); +if (this.os0 != null) { +this.os = this.os0; +this.append (s); +}this.sb = new JU.SB (); +this.sb.append (s); +this.$isBase64 = false; +return this.closeChannel (); +}return (this.sb == null ? null : this.sb.toString ()); +}this.closed = true; +{ +var data = (this.sb == null ? this.toByteArray() : +this.sb.toString()); if (typeof this.fileName == "function") { +this.fileName(data); } else { Jmol._doAjax(this.fileName, +null, data); } +}return null; +}); +Clazz.defineMethod (c$, "isBase64", +function () { +return this.$isBase64; +}); +Clazz.defineMethod (c$, "getBase64", +function () { +return JU.Base64.getBase64 (this.toByteArray ()).toString (); +}); +Clazz.defineMethod (c$, "toByteArray", +function () { +return (this.bytes != null ? this.bytes : Clazz.instanceOf (this.os, java.io.ByteArrayOutputStream) ? (this.os).toByteArray () : null); +}); +Clazz.defineMethod (c$, "close", +function () { +this.closeChannel (); +}); +Clazz.overrideMethod (c$, "toString", +function () { +if (this.bw != null) try { +this.bw.flush (); +} catch (e) { +if (Clazz.exceptionOf (e, java.io.IOException)) { +} else { +throw e; +} +} +if (this.sb != null) return this.closeChannel (); +return this.byteCount + " bytes"; +}); +Clazz.defineMethod (c$, "postByteArray", + function () { +var bytes = (this.sb == null ? this.toByteArray () : this.sb.toString ().getBytes ()); +return this.bytePoster.postByteArray (this.fileName, bytes); +}); +c$.isRemote = Clazz.defineMethod (c$, "isRemote", +function (fileName) { +if (fileName == null) return false; +var itype = JU.OC.urlTypeIndex (fileName); +return (itype >= 0 && itype != 4); +}, "~S"); +c$.isLocal = Clazz.defineMethod (c$, "isLocal", +function (fileName) { +if (fileName == null) return false; +var itype = JU.OC.urlTypeIndex (fileName); +return (itype < 0 || itype == 4); +}, "~S"); +c$.urlTypeIndex = Clazz.defineMethod (c$, "urlTypeIndex", +function (name) { +if (name == null) return -2; +for (var i = 0; i < JU.OC.urlPrefixes.length; ++i) { +if (name.startsWith (JU.OC.urlPrefixes[i])) { +return i; +}} +return -1; +}, "~S"); +Clazz.defineStatics (c$, +"urlPrefixes", Clazz.newArray (-1, ["http:", "https:", "sftp:", "ftp:", "file:"]), +"URL_LOCAL", 4); +});