From b24ac12ee50132643570511f908df0ebe0af1811 Mon Sep 17 00:00:00 2001 From: Joel Thibault Date: Wed, 16 Jan 2019 11:30:29 -0500 Subject: [PATCH] more CRAMIterator cleanup --- .../java/htsjdk/samtools/CRAMIterator.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/htsjdk/samtools/CRAMIterator.java b/src/main/java/htsjdk/samtools/CRAMIterator.java index a78cd6b571..51bb0ef023 100644 --- a/src/main/java/htsjdk/samtools/CRAMIterator.java +++ b/src/main/java/htsjdk/samtools/CRAMIterator.java @@ -29,7 +29,6 @@ import htsjdk.samtools.cram.structure.CramHeader; import htsjdk.samtools.cram.structure.Slice; import htsjdk.samtools.seekablestream.SeekableStream; -import htsjdk.samtools.util.Log; import java.io.IOException; import java.io.InputStream; @@ -39,7 +38,6 @@ import htsjdk.samtools.cram.CRAMException; public class CRAMIterator implements SAMRecordIterator { - private static final Log log = Log.getInstance(CRAMIterator.class); private final CountingInputStream countingInputStream; private final CramHeader cramHeader; private final ArrayList records; @@ -63,8 +61,7 @@ public ValidationStringency getValidationStringency() { return validationStringency; } - public void setValidationStringency( - final ValidationStringency validationStringency) { + public void setValidationStringency(final ValidationStringency validationStringency) { this.validationStringency = validationStringency; } @@ -75,11 +72,13 @@ public void setValidationStringency( private long samRecordIndex; private ArrayList cramRecords; - public CRAMIterator(final InputStream inputStream, final CRAMReferenceSource referenceSource, final ValidationStringency validationStringency) - throws IOException { + public CRAMIterator(final InputStream inputStream, + final CRAMReferenceSource referenceSource, + final ValidationStringency validationStringency) { if (null == referenceSource) { throw new CRAMException("A reference source is required for CRAM files"); } + this.countingInputStream = new CountingInputStream(inputStream); this.referenceSource = referenceSource; this.validationStringency = validationStringency; @@ -88,17 +87,20 @@ public CRAMIterator(final InputStream inputStream, final CRAMReferenceSource ref this.containerIterator = containerIterator; firstContainerOffset = this.countingInputStream.getCount(); - records = new ArrayList(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE); + records = new ArrayList<>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE); normalizer = new CramNormalizer(cramHeader.getSamFileHeader(), referenceSource); parser = new ContainerParser(cramHeader.getSamFileHeader()); } - public CRAMIterator(final SeekableStream seekableStream, final CRAMReferenceSource referenceSource, final long[] coordinates, final ValidationStringency validationStringency) - throws IOException { + public CRAMIterator(final SeekableStream seekableStream, + final CRAMReferenceSource referenceSource, + final long[] coordinates, + final ValidationStringency validationStringency) { if (null == referenceSource) { throw new CRAMException("A reference source is required for CRAM files"); } + this.countingInputStream = new CountingInputStream(seekableStream); this.referenceSource = referenceSource; this.validationStringency = validationStringency; @@ -107,15 +109,16 @@ public CRAMIterator(final SeekableStream seekableStream, final CRAMReferenceSour this.containerIterator = containerIterator; firstContainerOffset = containerIterator.getFirstContainerOffset(); - records = new ArrayList(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE); + records = new ArrayList<>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE); normalizer = new CramNormalizer(cramHeader.getSamFileHeader(), referenceSource); parser = new ContainerParser(cramHeader.getSamFileHeader()); } @Deprecated - public CRAMIterator(final SeekableStream seekableStream, final CRAMReferenceSource referenceSource, final long[] coordinates) - throws IOException { + public CRAMIterator(final SeekableStream seekableStream, + final CRAMReferenceSource referenceSource, + final long[] coordinates) { this(seekableStream, referenceSource, coordinates, ValidationStringency.DEFAULT_STRINGENCY); } @@ -123,8 +126,7 @@ public CramHeader getCramHeader() { return cramHeader; } - void nextContainer() throws IOException, IllegalArgumentException, - IllegalAccessException, CRAMException { + void nextContainer() throws IllegalArgumentException, CRAMException { if (containerIterator != null) { if (!containerIterator.hasNext()) { @@ -149,7 +151,7 @@ void nextContainer() throws IOException, IllegalArgumentException, records.clear(); if (cramRecords == null) - cramRecords = new ArrayList(container.nofRecords); + cramRecords = new ArrayList<>(container.nofRecords); else cramRecords.clear(); @@ -250,11 +252,7 @@ public boolean advanceToAlignmentInContainer(final int refIndex, final int pos) public boolean hasNext() { if (container != null && container.isEOF()) return false; if (!iterator.hasNext()) { - try { - nextContainer(); - } catch (IOException | IllegalAccessException e) { - throw new SAMException(e); - } + nextContainer(); } return !records.isEmpty();