/** * Write an end-of-file marker to the {@link OutputStream}. The specific EOF marker is chosen based on the CRAM version. * * @param version the CRAM version to assume * @param outputStream the stream to write to * @return the number of bytes written out * @throws IOException as per java IO contract */ public static long issueEOF(final Version version, final OutputStream outputStream) throws IOException { if (version.compatibleWith(CramVersions.CRAM_v3)) { outputStream.write(ZERO_F_EOF_MARKER); return ZERO_F_EOF_MARKER.length; } if (version.compatibleWith(CramVersions.CRAM_v2_1)) { outputStream.write(ZERO_B_EOF_MARKER); return ZERO_B_EOF_MARKER.length; } return 0; }
public boolean compatibleWith(final Version version) { return compareTo(version) >= 0; }
private static CramHeader readFormatDefinition(final InputStream inputStream) throws IOException { for (final byte magicByte : CramHeader.MAGIC) { if (magicByte != inputStream.read()) throw new RuntimeException("Unknown file format."); } final Version version = new Version(inputStream.read(), inputStream.read(), 0); final CramHeader header = new CramHeader(version, null, null); final DataInputStream dataInputStream = new DataInputStream(inputStream); dataInputStream.readFully(header.getId()); return header; }
private static CramHeader readFormatDefinition(final InputStream inputStream) throws IOException { for (final byte magicByte : CramHeader.MAGIC) { if (magicByte != inputStream.read()) throw new RuntimeException("Unknown file format."); } final Version version = new Version(inputStream.read(), inputStream.read(), 0); final CramHeader header = new CramHeader(version, null, null); final DataInputStream dataInputStream = new DataInputStream(inputStream); dataInputStream.readFully(header.getId()); return header; }
private static boolean checkEOF(htsjdk.samtools.cram.common.Version version, SeekableStream seekableStream) throws IOException { if (version.compatibleWith(CramVersions.CRAM_v3)) return streamEndsWith(seekableStream, CramIO.ZERO_F_EOF_MARKER); if (version.compatibleWith(CramVersions.CRAM_v2_1)) return streamEndsWith(seekableStream, CramIO.ZERO_B_EOF_MARKER); return false; }
public boolean compatibleWith(final Version version) { return compareTo(version) >= 0; }
/** * The method holds the behaviour for when the EOF marker is not found. Depending on the CRAM version this will be ignored, a warning * issued or an exception produced. * * @param version CRAM version to assume */ public static void eofNotFound(final Version version) { if (version.compatibleWith(CramVersions.CRAM_v3)) { log.error("Incomplete data: EOF marker not found."); throw new RuntimeException("EOF not found."); } if (version.compatibleWith(CramVersions.CRAM_v2_1)) log.warn("EOF marker not found, possibly incomplete file/stream."); } }
/** * The method holds the behaviour for when the EOF marker is not found. Depending on the CRAM version this will be ignored, a warning * issued or an exception produced. * * @param version CRAM version to assume */ public static void eofNotFound(final Version version) { if (version.compatibleWith(CramVersions.CRAM_v3)) { log.error("Incomplete data: EOF marker not found."); throw new RuntimeException("EOF not found."); } if (version.compatibleWith(CramVersions.CRAM_v2_1)) log.warn("EOF marker not found, possibly incomplete file/stream."); } }
/** * Write an end-of-file marker to the {@link OutputStream}. The specific EOF marker is chosen based on the CRAM version. * * @param version the CRAM version to assume * @param outputStream the stream to write to * @return the number of bytes written out */ public static long issueEOF(final Version version, final OutputStream outputStream) { try { if (version.compatibleWith(CramVersions.CRAM_v3)) { outputStream.write(ZERO_F_EOF_MARKER); return ZERO_F_EOF_MARKER.length; } if (version.compatibleWith(CramVersions.CRAM_v2_1)) { outputStream.write(ZERO_B_EOF_MARKER); return ZERO_B_EOF_MARKER.length; } } catch (final IOException e) { throw new RuntimeIOException(e); } return 0; }
/** * Check if the {@link SeekableStream} is properly terminated with a end-of-file marker. * * @param version CRAM version to assume * @param seekableStream the stream to read from * @return true if the stream ends with a correct EOF marker, false otherwise * @throws IOException as per java IO contract */ @SuppressWarnings("SimplifiableIfStatement") private static boolean checkEOF(final Version version, final SeekableStream seekableStream) throws IOException { if (version.compatibleWith(CramVersions.CRAM_v3)) return streamEndsWith(seekableStream, ZERO_F_EOF_MARKER); if (version.compatibleWith(CramVersions.CRAM_v2_1)) return streamEndsWith(seekableStream, ZERO_B_EOF_MARKER); return false; }
/** * Check if the {@link SeekableStream} is properly terminated with a end-of-file marker. * * @param version CRAM version to assume * @param seekableStream the stream to read from * @return true if the stream ends with a correct EOF marker, false otherwise * @throws IOException as per java IO contract */ @SuppressWarnings("SimplifiableIfStatement") private static boolean checkEOF(final Version version, final SeekableStream seekableStream) throws IOException { if (version.compatibleWith(CramVersions.CRAM_v3)) return streamEndsWith(seekableStream, ZERO_F_EOF_MARKER); if (version.compatibleWith(CramVersions.CRAM_v2_1)) return streamEndsWith(seekableStream, ZERO_B_EOF_MARKER); return false; }
final Block block; if (version.compatibleWith(CramVersions.CRAM_v3)) { final byte[] bytes = new byte[container.containerByteSize]; InputStreamUtils.readFully(inputStream, bytes, 0, bytes.length);
final Block block; if (version.compatibleWith(CramVersions.CRAM_v3)) { final byte[] bytes = new byte[container.containerByteSize]; InputStreamUtils.readFully(inputStream, bytes, 0, bytes.length);
if (version.compatibleWith(CramVersions.CRAM_v3)) cramRecord.setUnknownBases(record.getReadBases() == SAMRecord.NULL_SEQUENCE);
if (version.compatibleWith(CramVersions.CRAM_v3)) cramRecord.setUnknownBases(record.getReadBases() == SAMRecord.NULL_SEQUENCE);