diff --git a/src/main/java/htsjdk/samtools/cram/build/CRAMReferenceRegion.java b/src/main/java/htsjdk/samtools/cram/build/CRAMReferenceRegion.java index 514aeee6dd..8fc1c32bde 100644 --- a/src/main/java/htsjdk/samtools/cram/build/CRAMReferenceRegion.java +++ b/src/main/java/htsjdk/samtools/cram/build/CRAMReferenceRegion.java @@ -27,6 +27,7 @@ import htsjdk.samtools.SAMFileHeader; import htsjdk.samtools.SAMRecord; import htsjdk.samtools.SAMSequenceRecord; +import htsjdk.samtools.cram.CRAMException; import htsjdk.samtools.cram.ref.CRAMReferenceSource; import htsjdk.samtools.cram.ref.ReferenceContext; @@ -73,7 +74,7 @@ public byte[] getReferenceBases(final int referenceIndex) { final SAMSequenceRecord sequence = samFileHeader.getSequence(referenceIndex); referenceBases = referenceSource.getReferenceBases(sequence, true); if (referenceBases == null) { - throw new IllegalArgumentException( + throw new CRAMException( String.format( "A reference must be supplied (reference sequence %s not found).", sequence)); @@ -92,5 +93,4 @@ public void setEmbeddedReference(final byte[] embeddedReferenceBytes, final int referenceBasesContextID = embeddedReferenceIndex; referenceBases = embeddedReferenceBytes; } - } diff --git a/src/main/java/htsjdk/samtools/cram/build/CompressionHeaderFactory.java b/src/main/java/htsjdk/samtools/cram/build/CompressionHeaderFactory.java index 19375e745b..a6cebf3392 100644 --- a/src/main/java/htsjdk/samtools/cram/build/CompressionHeaderFactory.java +++ b/src/main/java/htsjdk/samtools/cram/build/CompressionHeaderFactory.java @@ -17,6 +17,7 @@ */ package htsjdk.samtools.cram.build; +import htsjdk.samtools.cram.CRAMException; import htsjdk.samtools.cram.common.MutableInt; import htsjdk.samtools.cram.compression.ExternalCompressor; import htsjdk.samtools.cram.encoding.*; @@ -422,7 +423,7 @@ private EncodingDetails buildEncodingForTag(final List re new ExternalByteArrayEncoding(tagID)).toEncodingDescriptor(); return details; default: - throw new IllegalArgumentException("Unknown tag type: " + (char) type); + throw new CRAMException("Unknown tag type: " + (char) type); } } @@ -468,9 +469,9 @@ static int getTagValueByteSize(final byte type, final Object value) { if (value instanceof long[]) { return 1 + 4 + ((long[]) value).length * 4; } - throw new RuntimeException("Unknown tag array class: " + value.getClass()); + throw new CRAMException("Unknown tag array class: " + value.getClass()); default: - throw new RuntimeException("Unknown tag type: " + (char) type); + throw new CRAMException("Unknown tag type: " + (char) type); } } } diff --git a/src/main/java/htsjdk/samtools/cram/build/CramContainerIterator.java b/src/main/java/htsjdk/samtools/cram/build/CramContainerIterator.java index 848b6feec1..6ce897a316 100644 --- a/src/main/java/htsjdk/samtools/cram/build/CramContainerIterator.java +++ b/src/main/java/htsjdk/samtools/cram/build/CramContainerIterator.java @@ -1,6 +1,7 @@ package htsjdk.samtools.cram.build; import htsjdk.samtools.SAMFileHeader; +import htsjdk.samtools.cram.CRAMException; import htsjdk.samtools.cram.io.CountingInputStream; import htsjdk.samtools.cram.structure.Container; import htsjdk.samtools.cram.structure.CramHeader; @@ -71,7 +72,7 @@ public Container next() { @Override public void remove() { - throw new RuntimeException("Read only iterator."); + throw new CRAMException("Read only iterator."); } public CramHeader getCramHeader() { diff --git a/src/main/java/htsjdk/samtools/cram/build/CramIO.java b/src/main/java/htsjdk/samtools/cram/build/CramIO.java index b0783426b4..7fcc36b2a8 100644 --- a/src/main/java/htsjdk/samtools/cram/build/CramIO.java +++ b/src/main/java/htsjdk/samtools/cram/build/CramIO.java @@ -19,6 +19,7 @@ import htsjdk.samtools.SAMFileHeader; import htsjdk.samtools.SAMTextHeaderCodec; +import htsjdk.samtools.cram.CRAMException; import htsjdk.samtools.cram.common.CramVersions; import htsjdk.samtools.cram.common.CRAMVersion; import htsjdk.samtools.cram.structure.*; @@ -26,6 +27,7 @@ import htsjdk.samtools.util.Log; import htsjdk.samtools.util.RuntimeIOException; +import javax.security.auth.login.CredentialException; import java.io.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -88,7 +90,7 @@ public static long writeCramEOF(final CRAMVersion cramVersion, final OutputStrea throw new RuntimeIOException(e); } - throw new IllegalArgumentException(String.format("Unrecognized CRAM version %s", cramVersion)); + throw new CRAMException(String.format("Unrecognized CRAM version %s", cramVersion)); } /** @@ -123,13 +125,13 @@ public static CramHeader readCramHeader(final InputStream inputStream) { try { for (final byte magicByte : CramHeader.MAGIC) { if (magicByte != inputStream.read()) { - throw new RuntimeException("Input does not have a valid CRAM header."); + throw new CRAMException("Input does not have a valid CRAM header."); } } final CRAMVersion cramVersion = new CRAMVersion(inputStream.read(), inputStream.read()); if (!CramVersions.isSupportedVersion(cramVersion)) { - throw new RuntimeException(String.format("CRAM version %s is not supported", cramVersion)); + throw new CRAMException(String.format("CRAM version %s is not supported", cramVersion)); } final CramHeader header = new CramHeader(cramVersion, null); diff --git a/src/main/java/htsjdk/samtools/cram/build/CramSpanContainerIterator.java b/src/main/java/htsjdk/samtools/cram/build/CramSpanContainerIterator.java index b7457ea1de..61792d9f15 100644 --- a/src/main/java/htsjdk/samtools/cram/build/CramSpanContainerIterator.java +++ b/src/main/java/htsjdk/samtools/cram/build/CramSpanContainerIterator.java @@ -1,5 +1,6 @@ package htsjdk.samtools.cram.build; +import htsjdk.samtools.cram.CRAMException; import htsjdk.samtools.cram.structure.Container; import htsjdk.samtools.seekablestream.SeekableStream; import htsjdk.samtools.util.RuntimeIOException; @@ -19,7 +20,7 @@ public final class CramSpanContainerIterator extends CramContainerIterator { private Iterator containerBoundaries; private Boundary currentBoundary; - private CramSpanContainerIterator(final SeekableStream seekableStream, final long[] coordinates) throws IOException { + private CramSpanContainerIterator(final SeekableStream seekableStream, final long[] coordinates) throws CRAMException { super(seekableStream); this.seekableStream = seekableStream; final List boundaries = new ArrayList<>(); @@ -70,7 +71,7 @@ public Boundary(final long start, final long end) { this.start = start; this.end = end; if (start >= end) { - throw new RuntimeException("Boundary start is greater than end."); + throw new CRAMException("Boundary start is greater than end."); } } @@ -91,7 +92,7 @@ public Container next() { } if (!hasNext()) { - throw new RuntimeException("No more containers in this boundary."); + throw new CRAMException("No more containers in this boundary."); } return new Container(getCramHeader().getCRAMVersion(), seekableStream, seekableStream.position());