j2sNative clean-up. Fixes problem with second try of sequence fetching
[jalview.git] / src / jalview / util / Platform.java
index b2bc3f4..68985b5 100644 (file)
@@ -26,6 +26,7 @@ import java.awt.Toolkit;
 import java.awt.event.MouseEvent;
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -463,7 +464,7 @@ public class Platform
     try
     {
       br = new BufferedReader(new InputStreamReader(response, "UTF-8"));
-      return parseJSON(br);
+      return new JSONParser().parse(br);
     } finally
     {
       if (br != null)
@@ -508,4 +509,38 @@ public class Platform
 
   }
 
+  /**
+   * Dump the input stream to an output file.
+   * 
+   * @param is
+   * @param outFile
+   * @throws IOException
+   *           if the file cannot be created or there is a problem reading the
+   *           input stream.
+   */
+  public static void streamToFile(InputStream is, File outFile)
+          throws IOException
+  {
+    if (!isJS() || /**
+                    * @j2sNative outFile.setBytes$O && outFile.setBytes$O(is) ||
+                    */
+            false)
+    {
+      return;
+    }
+    FileOutputStream fio = new FileOutputStream(outFile);
+    try
+    {
+      byte[] bb = new byte[32 * 1024];
+      int l;
+      while ((l = is.read(bb)) > 0)
+      {
+        fio.write(bb, 0, l);
+      }
+    } finally
+    {
+      fio.close();
+    }
+  }
+
 }