public boolean compatibleWith(final Version version) { return compareTo(version) >= 0; }
/** * <p> * Returns <code>true</code> if this HashMap maps one or more keys to this * value. * </p> * <p/> * <p> * Note that this method is identical in functionality to contains (which * predates the Map interface). * </p> * * @param value value whose presence in this HashMap is to be tested. * @return boolean <code>true</code> if the value is contained * @see java.util.Map * @since JDK1.2 */ public boolean containsValue(final Object value) { return contains(value); }
/** * 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 void add(final Integer value, final int inc) { MutableInt counter = countMap.get(value); if (counter == null) { counter = new MutableInt(); countMap.put(value, counter); } counter.value += inc; }
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; }
/** * Reads a CRAM container from the input stream. Returns an EOF container when there is no more data or the EOF marker found. * * @param version CRAM version to expect * @param inputStream the stream to read from * @return a new container object read from the stream */ public static Container readContainer(final Version version, final InputStream inputStream) { final Container container = readContainer(version.major, inputStream); if (container == null) { // this will cause System.exit(1): CramVersionPolicies.eofNotFound(version); return readContainer(version.major, new ByteArrayInputStream(CramIO.ZERO_B_EOF_MARKER)); } if (container.isEOF()) log.debug("EOF marker found, file/stream is complete."); return container; }
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 void add(final Integer value, final int inc) { MutableInt counter = countMap.get(value); if (counter == null) { counter = new MutableInt(); countMap.put(value, counter); } counter.value += inc; }
public boolean compatibleWith(final Version version) { return compareTo(version) >= 0; }
/** * <p> * Returns <code>true</code> if this HashMap maps one or more keys to this * value. * </p> * <p/> * <p> * Note that this method is identical in functionality to contains (which * predates the Map interface). * </p> * * @param value value whose presence in this HashMap is to be tested. * @return boolean <code>true</code> if the value is contained * @see java.util.Map * @since JDK1.2 */ public boolean containsValue(final Object value) { return contains(value); }
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; }
/** * 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; }
public void add(final int value) { MutableInt counter = countMap.get(value); if (counter == null) { counter = new MutableInt(); countMap.put(value, counter); } counter.value++; }
/** * 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; }
public void add(final int value) { MutableInt counter = countMap.get(value); if (counter == null) { counter = new MutableInt(); countMap.put(value, counter); } counter.value++; }
/** * 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; }