From 552acd59bb94adcb4b8f6012a0ecb64d05c799cd Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 11 Jan 2022 20:13:57 +0000 Subject: [PATCH] JAL-3703 fix Gff3 shared InputStream with embedded FASTA data --- src/jalview/io/AlignFile.java | 21 +++++++++++++++++++-- src/jalview/io/FastaFile.java | 11 ++++++++--- src/jalview/io/FeaturesFile.java | 4 +++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 338c4b2..b30fe33 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -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; + } } /** diff --git a/src/jalview/io/FastaFile.java b/src/jalview/io/FastaFile.java index 9acd7da..c698a31 100755 --- a/src/jalview/io/FastaFile.java +++ b/src/jalview/io/FastaFile.java @@ -20,14 +20,14 @@ */ package jalview.io; +import java.io.IOException; + import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; -import java.io.IOException; - /** * DOCUMENT ME! * @@ -69,7 +69,12 @@ public class FastaFile extends AlignFile public FastaFile(FileParse source) throws IOException { - super(source); + this(source, true); + } + + public FastaFile(FileParse source, boolean closeData) throws IOException + { + super(true, source, closeData); } public FastaFile(SequenceI[] seqs) diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index 7e62f6b..3f1cdd1 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -1393,7 +1393,9 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI } catch (IOException q) { } - FastaFile parser = new FastaFile(this); + // Opening a FastaFile object with the remainder of this object's dataIn. + // Tell the constructor to NOT close the dataIn when finished. + FastaFile parser = new FastaFile(this, false); List includedseqs = parser.getSeqs(); SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs); -- 1.7.10.2