/** * Complete the index, and close the output stream. * * @param finalVirtualOffset the virtual offset at which the next record would start if it were added to the file * @param dataFileLength the length of the data file in bytes */ public void finish(final long finalVirtualOffset, final long dataFileLength) { finish(finalVirtualOffset, dataFileLength, null, null); }
/** * Complete the index, and close the output stream. * * @param finalVirtualOffset the virtual offset at which the next record would start if it were added to the file * @param dataFileLength the length of the data file in bytes */ public void finish(final long finalVirtualOffset, final long dataFileLength) { finish(finalVirtualOffset, dataFileLength, null, null); }
/** * Complete the index, and close the output stream. * * @param finalVirtualOffset the virtual offset at which the next record would start if it were added to the file * @param dataFileLength the length of the data file in bytes * @param md5 the MD5 hash of the data file, or null if not specified * @param uuid the UUID for the data file, or null if not specified */ public void finish(final long finalVirtualOffset, final long dataFileLength, final byte[] md5, final byte[] uuid) { if (md5 != null && md5.length != 16) { throw new IllegalArgumentException("Invalid MD5 length: " + md5.length); } if (uuid != null && uuid.length != 16) { throw new IllegalArgumentException("Invalid UUID length: " + uuid.length); } final SBIIndex.Header header = new SBIIndex.Header(dataFileLength, md5 == null ? EMPTY_MD5 : md5, uuid == null ? EMPTY_UUID : uuid, recordCount, granularity); finish(header, finalVirtualOffset); }
/** * Complete the index, and close the output stream. * * @param finalVirtualOffset the virtual offset at which the next record would start if it were added to the file * @param dataFileLength the length of the data file in bytes * @param md5 the MD5 hash of the data file, or null if not specified * @param uuid the UUID for the data file, or null if not specified */ public void finish(final long finalVirtualOffset, final long dataFileLength, final byte[] md5, final byte[] uuid) { if (md5 != null && md5.length != 16) { throw new IllegalArgumentException("Invalid MD5 length: " + md5.length); } if (uuid != null && uuid.length != 16) { throw new IllegalArgumentException("Invalid UUID length: " + uuid.length); } final SBIIndex.Header header = new SBIIndex.Header(dataFileLength, md5 == null ? EMPTY_MD5 : md5, uuid == null ? EMPTY_UUID : uuid, recordCount, granularity); finish(header, finalVirtualOffset); }
indexWriter.finish(recordStart, in.length());
indexWriter.finish(recordStart, in.length());
private SBIIndex fromSAMRecords(final File bamFile, final long granularity) throws IOException { final BAMFileReader bamFileReader = bamFileReader(bamFile); try (CloseableIterator<SAMRecord> iterator = bamFileReader.getIterator(); ByteArrayOutputStream out = new ByteArrayOutputStream()) { final SBIIndexWriter indexWriter = new SBIIndexWriter(out, granularity); while (iterator.hasNext()) { processAlignment(indexWriter, iterator.next()); } indexWriter.finish(bamFileReader.getVirtualFilePointer(), bamFile.length()); return SBIIndex.load(new ByteArrayInputStream(out.toByteArray())); } }