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