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