/** * 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); }
void finish(final SBIIndex.Header header, final long finalVirtualOffset) { // complete writing the temp offsets file writeVirtualOffset(finalVirtualOffset); tempOffsetsCodec.close(); try (BinaryCodec binaryCodec = new BinaryCodec(out); InputStream tempOffsets = new BufferedInputStream(Files.newInputStream(tempOffsetsFile))) { // header binaryCodec.writeBytes(SBIIndex.SBI_MAGIC); binaryCodec.writeLong(header.getFileLength()); binaryCodec.writeBytes(header.getMd5()); binaryCodec.writeBytes(header.getUuid()); binaryCodec.writeLong(header.getTotalNumberOfRecords()); binaryCodec.writeLong(header.getGranularity()); binaryCodec.writeLong(virtualOffsetCount); // offsets IOUtil.copyStream(tempOffsets, out); } catch (IOException e) { throw new RuntimeIOException(e); } finally { try { Files.delete(tempOffsetsFile); } catch (IOException e) { throw new RuntimeIOException(e); } } } }
void finish(final SBIIndex.Header header, final long finalVirtualOffset) { // complete writing the temp offsets file writeVirtualOffset(finalVirtualOffset); tempOffsetsCodec.close(); try (BinaryCodec binaryCodec = new BinaryCodec(out); InputStream tempOffsets = new BufferedInputStream(Files.newInputStream(tempOffsetsFile))) { // header binaryCodec.writeBytes(SBIIndex.SBI_MAGIC); binaryCodec.writeLong(header.getFileLength()); binaryCodec.writeBytes(header.getMd5()); binaryCodec.writeBytes(header.getUuid()); binaryCodec.writeLong(header.getTotalNumberOfRecords()); binaryCodec.writeLong(header.getGranularity()); binaryCodec.writeLong(virtualOffsetCount); // offsets IOUtil.copyStream(tempOffsets, out); } catch (IOException e) { throw new RuntimeIOException(e); } finally { try { Files.delete(tempOffsetsFile); } catch (IOException e) { throw new RuntimeIOException(e); } } } }
/** * 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); }
private static Header readHeader(final BinaryCodec binaryCodec) { final byte[] buffer = new byte[SBI_MAGIC.length]; binaryCodec.readBytes(buffer); if (!Arrays.equals(buffer, SBI_MAGIC)) { throw new RuntimeException("Invalid file header in SBI: " + new String(buffer) + " (" + Arrays.toString(buffer) + ")"); } final long fileLength = binaryCodec.readLong(); final byte[] md5 = new byte[16]; binaryCodec.readBytes(md5); final byte[] uuid = new byte[16]; binaryCodec.readBytes(uuid); final long totalNumberOfRecords = binaryCodec.readLong(); final long granularity = binaryCodec.readLong(); return new Header(fileLength, md5, uuid, totalNumberOfRecords, granularity); }
private static Header readHeader(final BinaryCodec binaryCodec) { final byte[] buffer = new byte[SBI_MAGIC.length]; binaryCodec.readBytes(buffer); if (!Arrays.equals(buffer, SBI_MAGIC)) { throw new RuntimeException("Invalid file header in SBI: " + new String(buffer) + " (" + Arrays.toString(buffer) + ")"); } final long fileLength = binaryCodec.readLong(); final byte[] md5 = new byte[16]; binaryCodec.readBytes(md5); final byte[] uuid = new byte[16]; binaryCodec.readBytes(uuid); final long totalNumberOfRecords = binaryCodec.readLong(); final long granularity = binaryCodec.readLong(); return new Header(fileLength, md5, uuid, totalNumberOfRecords, granularity); }
/** * Returns the length of the data file in bytes. * * @return the length of the data file in bytes */ public long dataFileLength() { return header.getFileLength(); }
/** * Returns the granularity of the index, that is the number of alignments between subsequent entries in the index, * or zero if not specified. * @return the granularity of the index */ public long getGranularity() { return header.getGranularity(); }
/** * Returns the granularity of the index, that is the number of alignments between subsequent entries in the index, * or zero if not specified. * @return the granularity of the index */ public long getGranularity() { return header.getGranularity(); }
/** * Returns the length of the data file in bytes. * * @return the length of the data file in bytes */ public long dataFileLength() { return header.getFileLength(); }