X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Fio%2FFileParse.js;h=a16b90a035b6b4479994a669321eb79c1478d7ba;hp=51d1e87ddff75ab5caf4cdae5b11c5ab71f21263;hb=7301a2415adab88038b291fc54caeeb3a5a47a44;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/io/FileParse.js b/bin/jalview/io/FileParse.js index 51d1e87..a16b90a 100644 --- a/bin/jalview/io/FileParse.js +++ b/bin/jalview/io/FileParse.js @@ -1,250 +1,250 @@ -Clazz.declarePackage ("jalview.io"); -Clazz.load (null, "jalview.io.FileParse", ["jalview.io.AppletFormatAdapter", "jalview.util.MessageManager", "java.io.BufferedReader", "$.IOException", "$.InputStreamReader", "$.StringReader", "java.lang.Error", "java.net.URL", "java.util.zip.GZIPInputStream"], function () { -c$ = Clazz.decorateAsClass (function () { -this.dataName = "unknown source"; -this.inFile = null; -this.viewport = null; -this.exportSettings = null; -this.index = 1; -this.suffixSeparator = '#'; -this.newline = null; -this.suffix = null; -this.type = null; -this.dataIn = null; -this.errormessage = "UNITIALISED SOURCE"; -this.error = true; -this.warningMessage = null; -this.READAHEAD_LIMIT = 2048; -Clazz.instantialize (this, arguments); -}, jalview.io, "FileParse"); -Clazz.prepareFields (c$, function () { -this.newline = System.getProperty ("line.separator"); -}); -Clazz.defineMethod (c$, "setNewlineString", -function (nl) { -this.newline = nl; -}, "~S"); -Clazz.defineMethod (c$, "getNewlineString", -function () { -return this.newline; -}); -Clazz.makeConstructor (c$, -function () { -}); -Clazz.makeConstructor (c$, -function (from) { -if (from == null) { -throw new Error (jalview.util.MessageManager.getString ("error.implementation_error_null_fileparse")); -}if (from === this) { -return; -}this.index = ++from.index; -this.inFile = from.inFile; -this.suffixSeparator = from.suffixSeparator; -this.suffix = from.suffix; -this.errormessage = from.errormessage; -this.error = false; -this.type = from.type; -this.dataIn = from.dataIn; -if (this.dataIn != null) { -this.mark (); -}this.dataName = from.dataName; -}, "jalview.io.FileParse"); -Clazz.defineMethod (c$, "tryAsGzipSource", -($fz = function (inputStream) { -var inData = new java.io.BufferedReader ( new java.io.InputStreamReader ( new java.util.zip.GZIPInputStream (inputStream))); -inData.mark (2048); -inData.read (); -inData.reset (); -return inData; -}, $fz.isPrivate = true, $fz), "java.io.InputStream"); -Clazz.defineMethod (c$, "checkURLSource", -($fz = function (fileStr) { -this.errormessage = "URL NOT FOUND"; -var url = new java.net.URL (fileStr); -var e = null; -if (fileStr.toLowerCase ().endsWith (".gz")) { -try { -var inputStream = url.openStream (); -this.dataIn = this.tryAsGzipSource (inputStream); -this.dataName = fileStr; -return false; -} catch (ex) { -if (Clazz.exceptionOf (ex, Exception)) { -e = ex; -} else { -throw ex; -} -} -}try { -this.dataIn = new java.io.BufferedReader ( new java.io.InputStreamReader (url.openStream ())); -} catch (q) { -if (Clazz.exceptionOf (q, java.io.IOException)) { -if (e != null) { -throw new java.io.IOException (jalview.util.MessageManager.getString ("exception.failed_to_resolve_gzip_stream"), e); -}throw q; -} else { -throw q; -} -} -this.dataName = fileStr; -return false; -}, $fz.isPrivate = true, $fz), "~S"); -Clazz.defineMethod (c$, "extractSuffix", -($fz = function (fileStr) { -var sfpos = fileStr.lastIndexOf (this.suffixSeparator); -if (sfpos > -1 && sfpos < fileStr.length - 1) { -this.suffix = fileStr.substring (sfpos + 1); -return fileStr.substring (0, sfpos); -}return null; -}, $fz.isPrivate = true, $fz), "~S"); -Clazz.makeConstructor (c$, -function (fileStr, type) { -this.type = type; -this.error = false; -if (type.equals (jalview.io.AppletFormatAdapter.FILE)) { -{ -}} else if (type.equals (jalview.io.AppletFormatAdapter.URL)) { -try { -try { -this.checkURLSource (fileStr); -if (this.suffixSeparator == '#') { -this.extractSuffix (fileStr); -}} catch (e) { -if (Clazz.exceptionOf (e, java.io.IOException)) { -var suffixLess = this.extractSuffix (fileStr); -if (suffixLess == null) { -throw (e); -} else { -try { -this.checkURLSource (suffixLess); -} catch (e2) { -if (Clazz.exceptionOf (e2, java.io.IOException)) { -this.errormessage = "BAD URL WITH OR WITHOUT SUFFIX"; -throw (e); -} else { -throw e2; -} -} -}} else { -throw e; -} -} -} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -this.errormessage = "CANNOT ACCESS DATA AT URL '" + fileStr + "' (" + e.getMessage () + ")"; -this.error = true; -} else { -throw e; -} -} -} else if (type.equals (jalview.io.AppletFormatAdapter.PASTE)) { -this.errormessage = "PASTE INACCESSIBLE!"; -this.dataIn = new java.io.BufferedReader ( new java.io.StringReader (fileStr)); -this.dataName = "Paste"; -} else if (type.equals (jalview.io.AppletFormatAdapter.CLASSLOADER)) { -this.errormessage = "RESOURCE CANNOT BE LOCATED"; -var is = this.getClass ().getResourceAsStream ("/" + fileStr); -if (is == null) { -var suffixLess = this.extractSuffix (fileStr); -if (suffixLess != null) { -is = this.getClass ().getResourceAsStream ("/" + suffixLess); -}}if (is != null) { -this.dataIn = new java.io.BufferedReader ( new java.io.InputStreamReader (is)); -this.dataName = fileStr; -} else { -this.error = true; -}} else { -this.errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '" + (type != null ? type : "null") + "'"; -this.error = true; -}if (this.dataIn == null || this.error) { -throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.failed_to_read_data_from_source", Clazz.newArray (-1, [this.errormessage]))); -}this.error = false; -this.dataIn.mark (2048); -}, "~S,~S"); -Clazz.defineMethod (c$, "mark", -function () { -if (this.dataIn != null) { -this.dataIn.mark (2048); -} else { -throw new java.io.IOException (jalview.util.MessageManager.getString ("exception.no_init_source_stream")); -}}); -Clazz.defineMethod (c$, "nextLine", -function () { -if (!this.error) { -return this.dataIn.readLine (); -}throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.invalid_source_stream", Clazz.newArray (-1, [this.errormessage]))); -}); -Clazz.defineMethod (c$, "isExporting", -function () { -return !this.error && this.dataIn == null; -}); -Clazz.defineMethod (c$, "isValid", -function () { -return !this.error; -}); -Clazz.defineMethod (c$, "close", -function () { -this.errormessage = "EXCEPTION ON CLOSE"; -this.error = true; -this.dataIn.close (); -this.dataIn = null; -this.errormessage = "SOURCE IS CLOSED"; -}); -Clazz.defineMethod (c$, "reset", -function () { -if (this.dataIn != null && !this.error) { -this.dataIn.reset (); -} else { -throw new java.io.IOException (jalview.util.MessageManager.getString ("error.implementation_error_reset_called_for_invalid_source")); -}}); -Clazz.defineMethod (c$, "hasWarningMessage", -function () { -return (this.warningMessage != null && this.warningMessage.length > 0); -}); -Clazz.defineMethod (c$, "getWarningMessage", -function () { -return this.warningMessage; -}); -Clazz.defineMethod (c$, "getInFile", -function () { -if (this.inFile != null) { -return this.inFile.getAbsolutePath () + " (" + this.index + ")"; -} else { -return "From Paste + (" + this.index + ")"; -}}); -Clazz.defineMethod (c$, "getDataName", -function () { -return this.dataName; -}); -Clazz.defineMethod (c$, "setDataName", -function (dataname) { -this.dataName = dataname; -}, "~S"); -Clazz.defineMethod (c$, "getReader", -function () { -if (this.dataIn != null) { -return this.dataIn; -}return null; -}); -Clazz.defineMethod (c$, "getViewport", -function () { -return this.viewport; -}); -Clazz.defineMethod (c$, "setViewport", -function (viewport) { -this.viewport = viewport; -}, "jalview.api.AlignViewportI"); -Clazz.defineMethod (c$, "getExportSettings", -function () { -return this.exportSettings; -}); -Clazz.defineMethod (c$, "setExportSettings", -function (exportSettings) { -this.exportSettings = exportSettings; -}, "jalview.api.AlignExportSettingI"); -Clazz.defineMethod (c$, "configureForView", -function (avpanel) { -if (avpanel != null) { -this.setViewport (avpanel.getAlignViewport ()); -}}, "jalview.api.AlignmentViewPanel"); -}); +Clazz.declarePackage ("jalview.io"); +Clazz.load (null, "jalview.io.FileParse", ["jalview.io.AppletFormatAdapter", "jalview.util.MessageManager", "java.io.BufferedReader", "$.IOException", "$.InputStreamReader", "$.StringReader", "java.lang.Error", "java.net.URL", "java.util.zip.GZIPInputStream"], function () { +c$ = Clazz.decorateAsClass (function () { +this.dataName = "unknown source"; +this.inFile = null; +this.viewport = null; +this.exportSettings = null; +this.index = 1; +this.suffixSeparator = '#'; +this.newline = null; +this.suffix = null; +this.type = null; +this.dataIn = null; +this.errormessage = "UNITIALISED SOURCE"; +this.error = true; +this.warningMessage = null; +this.READAHEAD_LIMIT = 2048; +Clazz.instantialize (this, arguments); +}, jalview.io, "FileParse"); +Clazz.prepareFields (c$, function () { +this.newline = System.getProperty ("line.separator"); +}); +Clazz.defineMethod (c$, "setNewlineString", +function (nl) { +this.newline = nl; +}, "~S"); +Clazz.defineMethod (c$, "getNewlineString", +function () { +return this.newline; +}); +Clazz.makeConstructor (c$, +function () { +}); +Clazz.makeConstructor (c$, +function (from) { +if (from == null) { +throw new Error (jalview.util.MessageManager.getString ("error.implementation_error_null_fileparse")); +}if (from === this) { +return; +}this.index = ++from.index; +this.inFile = from.inFile; +this.suffixSeparator = from.suffixSeparator; +this.suffix = from.suffix; +this.errormessage = from.errormessage; +this.error = false; +this.type = from.type; +this.dataIn = from.dataIn; +if (this.dataIn != null) { +this.mark (); +}this.dataName = from.dataName; +}, "jalview.io.FileParse"); +Clazz.defineMethod (c$, "tryAsGzipSource", +($fz = function (inputStream) { +var inData = new java.io.BufferedReader ( new java.io.InputStreamReader ( new java.util.zip.GZIPInputStream (inputStream))); +inData.mark (2048); +inData.read (); +inData.reset (); +return inData; +}, $fz.isPrivate = true, $fz), "java.io.InputStream"); +Clazz.defineMethod (c$, "checkURLSource", +($fz = function (fileStr) { +this.errormessage = "URL NOT FOUND"; +var url = new java.net.URL (fileStr); +var e = null; +if (fileStr.toLowerCase ().endsWith (".gz")) { +try { +var inputStream = url.openStream (); +this.dataIn = this.tryAsGzipSource (inputStream); +this.dataName = fileStr; +return false; +} catch (ex) { +if (Clazz.exceptionOf (ex, Exception)) { +e = ex; +} else { +throw ex; +} +} +}try { +this.dataIn = new java.io.BufferedReader ( new java.io.InputStreamReader (url.openStream ())); +} catch (q) { +if (Clazz.exceptionOf (q, java.io.IOException)) { +if (e != null) { +throw new java.io.IOException (jalview.util.MessageManager.getString ("exception.failed_to_resolve_gzip_stream"), e); +}throw q; +} else { +throw q; +} +} +this.dataName = fileStr; +return false; +}, $fz.isPrivate = true, $fz), "~S"); +Clazz.defineMethod (c$, "extractSuffix", +($fz = function (fileStr) { +var sfpos = fileStr.lastIndexOf (this.suffixSeparator); +if (sfpos > -1 && sfpos < fileStr.length - 1) { +this.suffix = fileStr.substring (sfpos + 1); +return fileStr.substring (0, sfpos); +}return null; +}, $fz.isPrivate = true, $fz), "~S"); +Clazz.makeConstructor (c$, +function (fileStr, type) { +this.type = type; +this.error = false; +if (type.equals (jalview.io.AppletFormatAdapter.FILE)) { +{ +}} else if (type.equals (jalview.io.AppletFormatAdapter.URL)) { +try { +try { +this.checkURLSource (fileStr); +if (this.suffixSeparator == '#') { +this.extractSuffix (fileStr); +}} catch (e) { +if (Clazz.exceptionOf (e, java.io.IOException)) { +var suffixLess = this.extractSuffix (fileStr); +if (suffixLess == null) { +throw (e); +} else { +try { +this.checkURLSource (suffixLess); +} catch (e2) { +if (Clazz.exceptionOf (e2, java.io.IOException)) { +this.errormessage = "BAD URL WITH OR WITHOUT SUFFIX"; +throw (e); +} else { +throw e2; +} +} +}} else { +throw e; +} +} +} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +this.errormessage = "CANNOT ACCESS DATA AT URL '" + fileStr + "' (" + e.getMessage () + ")"; +this.error = true; +} else { +throw e; +} +} +} else if (type.equals (jalview.io.AppletFormatAdapter.PASTE)) { +this.errormessage = "PASTE INACCESSIBLE!"; +this.dataIn = new java.io.BufferedReader ( new java.io.StringReader (fileStr)); +this.dataName = "Paste"; +} else if (type.equals (jalview.io.AppletFormatAdapter.CLASSLOADER)) { +this.errormessage = "RESOURCE CANNOT BE LOCATED"; +var is = this.getClass ().getResourceAsStream ("/" + fileStr); +if (is == null) { +var suffixLess = this.extractSuffix (fileStr); +if (suffixLess != null) { +is = this.getClass ().getResourceAsStream ("/" + suffixLess); +}}if (is != null) { +this.dataIn = new java.io.BufferedReader ( new java.io.InputStreamReader (is)); +this.dataName = fileStr; +} else { +this.error = true; +}} else { +this.errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '" + (type != null ? type : "null") + "'"; +this.error = true; +}if (this.dataIn == null || this.error) { +throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.failed_to_read_data_from_source", Clazz.newArray (-1, [this.errormessage]))); +}this.error = false; +this.dataIn.mark (2048); +}, "~S,~S"); +Clazz.defineMethod (c$, "mark", +function () { +if (this.dataIn != null) { +this.dataIn.mark (2048); +} else { +throw new java.io.IOException (jalview.util.MessageManager.getString ("exception.no_init_source_stream")); +}}); +Clazz.defineMethod (c$, "nextLine", +function () { +if (!this.error) { +return this.dataIn.readLine (); +}throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.invalid_source_stream", Clazz.newArray (-1, [this.errormessage]))); +}); +Clazz.defineMethod (c$, "isExporting", +function () { +return !this.error && this.dataIn == null; +}); +Clazz.defineMethod (c$, "isValid", +function () { +return !this.error; +}); +Clazz.defineMethod (c$, "close", +function () { +this.errormessage = "EXCEPTION ON CLOSE"; +this.error = true; +this.dataIn.close (); +this.dataIn = null; +this.errormessage = "SOURCE IS CLOSED"; +}); +Clazz.defineMethod (c$, "reset", +function () { +if (this.dataIn != null && !this.error) { +this.dataIn.reset (); +} else { +throw new java.io.IOException (jalview.util.MessageManager.getString ("error.implementation_error_reset_called_for_invalid_source")); +}}); +Clazz.defineMethod (c$, "hasWarningMessage", +function () { +return (this.warningMessage != null && this.warningMessage.length > 0); +}); +Clazz.defineMethod (c$, "getWarningMessage", +function () { +return this.warningMessage; +}); +Clazz.defineMethod (c$, "getInFile", +function () { +if (this.inFile != null) { +return this.inFile.getAbsolutePath () + " (" + this.index + ")"; +} else { +return "From Paste + (" + this.index + ")"; +}}); +Clazz.defineMethod (c$, "getDataName", +function () { +return this.dataName; +}); +Clazz.defineMethod (c$, "setDataName", +function (dataname) { +this.dataName = dataname; +}, "~S"); +Clazz.defineMethod (c$, "getReader", +function () { +if (this.dataIn != null) { +return this.dataIn; +}return null; +}); +Clazz.defineMethod (c$, "getViewport", +function () { +return this.viewport; +}); +Clazz.defineMethod (c$, "setViewport", +function (viewport) { +this.viewport = viewport; +}, "jalview.api.AlignViewportI"); +Clazz.defineMethod (c$, "getExportSettings", +function () { +return this.exportSettings; +}); +Clazz.defineMethod (c$, "setExportSettings", +function (exportSettings) { +this.exportSettings = exportSettings; +}, "jalview.api.AlignExportSettingI"); +Clazz.defineMethod (c$, "configureForView", +function (avpanel) { +if (avpanel != null) { +this.setViewport (avpanel.getAlignViewport ()); +}}, "jalview.api.AlignmentViewPanel"); +});