JAL-3032 part2 local file reading by JFileChooser
[jalview.git] / src / jalview / io / FileParse.java
index bf0a844..7e1940f 100755 (executable)
@@ -58,6 +58,8 @@ public class FileParse
 
   public File inFile = null;
 
+  public byte[] bytes; // from JavaScript
+
   /**
    * a viewport associated with the current file operation. May be null. May
    * move to different object.
@@ -315,12 +317,41 @@ public class FileParse
   public FileParse(String fileStr, DataSourceType sourceType)
           throws MalformedURLException, IOException
   {
+
+    this(null, fileStr, sourceType, false);
+  }
+
+  public FileParse(File file, DataSourceType sourceType)
+          throws MalformedURLException, IOException
+  {
+
+    this(file, file.getPath(), sourceType, true);
+  }
+
+  private FileParse(File file, String fileStr, DataSourceType sourceType,
+          boolean isFileObject) throws MalformedURLException, IOException
+  {
+
+    /**
+     * @j2sNative
+     * 
+     *            this.bytes = file && file._bytes;
+     * 
+     */
     this.dataSourceType = sourceType;
     error = false;
 
     if (sourceType == DataSourceType.FILE)
     {
-      if (checkFileSource(fileStr))
+
+      if (bytes != null)
+      {
+        // this will be from JavaScript
+        inFile = file;
+        dataIn = new BufferedReader(new StringReader(new String(bytes)));
+        dataName = fileStr;
+      }
+      else if (checkFileSource(fileStr))
       {
         String suffixLess = extractSuffix(fileStr);
         if (suffixLess != null)
@@ -434,7 +465,8 @@ public class FileParse
     {
       // pass up the reason why we have no source to read from
       throw new IOException(MessageManager.formatMessage(
-              "exception.failed_to_read_data_from_source", new String[]
+              "exception.failed_to_read_data_from_source",
+              new String[]
               { errormessage }));
     }
     error = false;