1 Clazz.declarePackage ("jalview.io");
2 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 () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.dataName = "unknown source";
7 this.exportSettings = null;
9 this.suffixSeparator = '#';
14 this.errormessage = "UNITIALISED SOURCE";
16 this.warningMessage = null;
17 this.READAHEAD_LIMIT = 2048;
18 Clazz.instantialize (this, arguments);
19 }, jalview.io, "FileParse");
20 Clazz.prepareFields (c$, function () {
21 this.newline = System.getProperty ("line.separator");
23 Clazz.defineMethod (c$, "setNewlineString",
27 Clazz.defineMethod (c$, "getNewlineString",
31 Clazz.makeConstructor (c$,
34 Clazz.makeConstructor (c$,
37 throw new Error (jalview.util.MessageManager.getString ("error.implementation_error_null_fileparse"));
40 }this.index = ++from.index;
41 this.inFile = from.inFile;
42 this.suffixSeparator = from.suffixSeparator;
43 this.suffix = from.suffix;
44 this.errormessage = from.errormessage;
46 this.type = from.type;
47 this.dataIn = from.dataIn;
48 if (this.dataIn != null) {
50 }this.dataName = from.dataName;
51 }, "jalview.io.FileParse");
52 Clazz.defineMethod (c$, "tryAsGzipSource",
53 function (inputStream) {
54 var inData = new java.io.BufferedReader ( new java.io.InputStreamReader ( new java.util.zip.GZIPInputStream (inputStream)));
59 }, "java.io.InputStream");
60 Clazz.defineMethod (c$, "checkURLSource",
62 this.errormessage = "URL NOT FOUND";
63 var url = new java.net.URL (fileStr);
65 if (fileStr.toLowerCase ().endsWith (".gz")) {
67 var inputStream = url.openStream ();
68 this.dataIn = this.tryAsGzipSource (inputStream);
69 this.dataName = fileStr;
72 if (Clazz.exceptionOf (ex, Exception)) {
79 this.dataIn = new java.io.BufferedReader ( new java.io.InputStreamReader (url.openStream ()));
81 if (Clazz.exceptionOf (q, java.io.IOException)) {
83 throw new java.io.IOException (jalview.util.MessageManager.getString ("exception.failed_to_resolve_gzip_stream"), e);
89 this.dataName = fileStr;
92 Clazz.defineMethod (c$, "extractSuffix",
94 var sfpos = fileStr.lastIndexOf (this.suffixSeparator);
95 if (sfpos > -1 && sfpos < fileStr.length - 1) {
96 this.suffix = fileStr.substring (sfpos + 1);
97 return fileStr.substring (0, sfpos);
100 Clazz.makeConstructor (c$,
101 function (fileStr, type) {
104 if (type.equals (jalview.io.AppletFormatAdapter.FILE)) {
106 }} else if (type.equals (jalview.io.AppletFormatAdapter.URL)) {
109 this.checkURLSource (fileStr);
110 if (this.suffixSeparator == '#') {
111 this.extractSuffix (fileStr);
113 if (Clazz.exceptionOf (e, java.io.IOException)) {
114 var suffixLess = this.extractSuffix (fileStr);
115 if (suffixLess == null) {
119 this.checkURLSource (suffixLess);
121 if (Clazz.exceptionOf (e2, java.io.IOException)) {
122 this.errormessage = "BAD URL WITH OR WITHOUT SUFFIX";
133 if (Clazz.exceptionOf (e, Exception)) {
134 this.errormessage = "CANNOT ACCESS DATA AT URL '" + fileStr + "' (" + e.getMessage () + ")";
140 } else if (type.equals (jalview.io.AppletFormatAdapter.PASTE)) {
141 this.errormessage = "PASTE INACCESSIBLE!";
142 this.dataIn = new java.io.BufferedReader ( new java.io.StringReader (fileStr));
143 this.dataName = "Paste";
144 } else if (type.equals (jalview.io.AppletFormatAdapter.CLASSLOADER)) {
145 this.errormessage = "RESOURCE CANNOT BE LOCATED";
146 var is = this.getClass ().getResourceAsStream ("/" + fileStr);
148 var suffixLess = this.extractSuffix (fileStr);
149 if (suffixLess != null) {
150 is = this.getClass ().getResourceAsStream ("/" + suffixLess);
152 this.dataIn = new java.io.BufferedReader ( new java.io.InputStreamReader (is));
153 this.dataName = fileStr;
157 this.errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '" + (type != null ? type : "null") + "'";
159 }if (this.dataIn == null || this.error) {
160 throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.failed_to_read_data_from_source", Clazz.newArray (-1, [this.errormessage])));
162 this.dataIn.mark (2048);
164 Clazz.defineMethod (c$, "mark",
166 if (this.dataIn != null) {
167 this.dataIn.mark (2048);
169 throw new java.io.IOException (jalview.util.MessageManager.getString ("exception.no_init_source_stream"));
171 Clazz.defineMethod (c$, "nextLine",
174 return this.dataIn.readLine ();
175 }throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.invalid_source_stream", Clazz.newArray (-1, [this.errormessage])));
177 Clazz.defineMethod (c$, "isExporting",
179 return !this.error && this.dataIn == null;
181 Clazz.defineMethod (c$, "isValid",
185 Clazz.defineMethod (c$, "close",
187 this.errormessage = "EXCEPTION ON CLOSE";
189 this.dataIn.close ();
191 this.errormessage = "SOURCE IS CLOSED";
193 Clazz.defineMethod (c$, "reset",
195 if (this.dataIn != null && !this.error) {
196 this.dataIn.reset ();
198 throw new java.io.IOException (jalview.util.MessageManager.getString ("error.implementation_error_reset_called_for_invalid_source"));
200 Clazz.defineMethod (c$, "hasWarningMessage",
202 return (this.warningMessage != null && this.warningMessage.length > 0);
204 Clazz.defineMethod (c$, "getWarningMessage",
206 return this.warningMessage;
208 Clazz.defineMethod (c$, "getInFile",
210 if (this.inFile != null) {
211 return this.inFile.getAbsolutePath () + " (" + this.index + ")";
213 return "From Paste + (" + this.index + ")";
215 Clazz.defineMethod (c$, "getDataName",
217 return this.dataName;
219 Clazz.defineMethod (c$, "setDataName",
220 function (dataname) {
221 this.dataName = dataname;
223 Clazz.defineMethod (c$, "getReader",
225 if (this.dataIn != null) {
229 Clazz.defineMethod (c$, "getViewport",
231 return this.viewport;
233 Clazz.defineMethod (c$, "setViewport",
234 function (viewport) {
235 this.viewport = viewport;
236 }, "jalview.api.AlignViewportI");
237 Clazz.defineMethod (c$, "getExportSettings",
239 return this.exportSettings;
241 Clazz.defineMethod (c$, "setExportSettings",
242 function (exportSettings) {
243 this.exportSettings = exportSettings;
244 }, "jalview.api.AlignExportSettingI");
245 Clazz.defineMethod (c$, "configureForView",
247 if (avpanel != null) {
248 this.setViewport (avpanel.getAlignViewport ());
249 }}, "jalview.api.AlignmentViewPanel");