JAL-1601 Read full file before passing to FileParse
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 12 Mar 2024 12:50:07 +0000 (13:50 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 12 Mar 2024 12:50:07 +0000 (13:50 +0100)
FileParse fails to read file from the URL in javascript.
It's related to errors in AjaxURLConnection implementation in j2s.

src/jalview/ws2/client/jpred4/JPred4WSClient.java

index 3782723..fccd876 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.ws2.client.jpred4;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.List;
 
@@ -113,14 +114,24 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI
   @Override
   public AlignFile getAlignmentFile(WebServiceJobHandle job) throws IOException
   {
-    var url = client.getResultURL(job.getJobId(), ResultTypes.PSIBLAST_ALIGN);
-    return new FastaFile(url.toString(), DataSourceType.URL);
+    var stream = client.getResultStream(job.getJobId(), ResultTypes.PSIBLAST_ALIGN);
+    var buffer = new byte[2048];
+    var file = new ByteArrayOutputStream();
+    var len = 0;
+    while ((len= stream.read(buffer)) >= 0)
+      file.write(buffer, 0, len);
+    return new FastaFile(file.toString("UTF-8"), DataSourceType.PASTE);
   }
 
   @Override
   public JPredFile getPredictionFile(WebServiceJobHandle job) throws IOException
   {
-    var url = client.getResultURL(job.getJobId(), ResultTypes.CONCISE);
-    return new JPredFile(url.toString(), DataSourceType.URL);
+    var stream = client.getResultStream(job.getJobId(), ResultTypes.CONCISE);
+    var buffer = new byte[2048];
+    var file = new ByteArrayOutputStream();
+    var len = 0;
+    while ((len= stream.read(buffer)) >= 0)
+      file.write(buffer, 0, len);
+    return new JPredFile(file.toString("UTF-8"), DataSourceType.PASTE);
   }
 }