JAL-3703 fix Gff3 shared InputStream with embedded FASTA data
[jalview.git] / src / jalview / io / AlignFile.java
index 9e426ab..3202ac9 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
    */
@@ -165,6 +167,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();
 
@@ -174,7 +182,7 @@ public abstract class AlignFile extends FileParse
 
     if (parseImmediately)
     {
-      doParse();
+      doParse(closeData);
     }
   }
 
@@ -185,6 +193,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(
@@ -193,7 +206,11 @@ public abstract class AlignFile extends FileParse
     }
     parseCalled = true;
     parse();
-    dataIn.close();
+    if (closeData && !dataClosed)
+    {
+      dataIn.close();
+      dataClosed = true;
+    }
   }
 
   /**