JAL-3703 fix Gff3 shared InputStream with embedded FASTA data
[jalview.git] / src / jalview / io / AlignFile.java
index 338c4b2..b30fe33 100755 (executable)
@@ -79,6 +79,8 @@ public abstract class AlignFile extends FileParse
 
   private boolean parseImmediately = true;
 
+  private boolean dataClosed = false;
+
   /**
    * @return if doParse() was called at construction time
    */
@@ -164,6 +166,12 @@ public abstract class AlignFile extends FileParse
   public AlignFile(boolean parseImmediately, FileParse source)
           throws IOException
   {
+    this(parseImmediately, source, true);
+  }
+
+  public AlignFile(boolean parseImmediately, FileParse source,
+          boolean closeData) throws IOException
+  {
     super(source);
     initData();
 
@@ -173,7 +181,7 @@ public abstract class AlignFile extends FileParse
 
     if (parseImmediately)
     {
-      doParse();
+      doParse(closeData);
     }
   }
 
@@ -184,6 +192,11 @@ public abstract class AlignFile extends FileParse
    */
   public void doParse() throws IOException
   {
+    doParse(true);
+  }
+
+  public void doParse(boolean closeData) throws IOException
+  {
     if (parseCalled)
     {
       throw new IOException(
@@ -192,7 +205,11 @@ public abstract class AlignFile extends FileParse
     }
     parseCalled = true;
     parse();
-    dataIn.close();
+    if (closeData && !dataClosed)
+    {
+      dataIn.close();
+      dataClosed = true;
+    }
   }
 
   /**