Source:
<code>public static void mergeParts(final String partDirectory, final String outputFile, final SAMFormat samOutputFormat, final SAMFileHeader header) throws IOException { final String successFile = partDirectory + "/_SUCCESS"; final Path successPath = asPath(successFile); if (!Files.exists(successPath)) { throw new NoSuchFileException(successFile, null, "Unable to find _SUCCESS file"); } final Path partPath = asPath(partDirectory); final Path outputPath = asPath(outputFile); if (partPath.equals(outputPath)) { throw new IllegalArgumentException("Cannot merge parts into output with same " + "path: " + partPath); } List<Path> parts = getFilesMatching(partPath, "glob:**/part-[mr]-[0-9][0-9][0-9][0-9][0-9]*", SplittingBAMIndexer.OUTPUT_FILE_EXTENSION); if (parts.isEmpty()) { throw new IllegalArgumentException("Could not write bam file because no part " + "files were found in " + partPath); } <START> Files.deleteIfExists(outputPath); <END> long headerLength; try (final CountingOutputStream out = new CountingOutputStream(Files.newOutputStream(outputPath))) { if (header != null) { new SAMOutputPreparer().prepareForRecords(out, samOutputFormat, header); } headerLength = out.getCount(); mergeInto(parts, out); writeTerminatorBlock(out, samOutputFormat); } long fileLength = Files.size(outputPath); final Path outputSplittingBaiPath = outputPath.resolveSibling( outputPath.getFileName() + SplittingBAMIndexer.OUTPUT_FILE_EXTENSION); try (final OutputStream out = Files.newOutputStream(outputSplittingBaiPath)) { mergeSplittingBaiFiles(out, partPath, headerLength, fileLength); } catch (IOException e) { deleteRecursive(outputSplittingBaiPath); } deleteRecursive(partPath); }</code><technical_language>deleting target index</technical_language>

Target:
public static void mergeParts(final String partDirectory, final String outputFile, final SAMFormat samOutputFormat, final SAMFileHeader header) throws IOException { final String successFile = partDirectory + "/_SUCCESS"; final Path successPath = asPath(successFile); if (!Files.exists(successPath)) { throw new NoSuchFileException(successFile, null, "Unable to find _SUCCESS file"); } final Path partPath = asPath(partDirectory); final Path outputPath = asPath(outputFile); if (partPath.equals(outputPath)) { throw new IllegalArgumentException("Cannot merge parts into output with same " + "path: " + partPath); } List<Path> parts = getFilesMatching(partPath, NIOFileUtil.PARTS_GLOB, SplittingBAMIndexer.OUTPUT_FILE_EXTENSION); if (parts.isEmpty()) { throw new IllegalArgumentException("Could not write bam file because no part " + "files were found in " + partPath); } Files.deleteIfExists(outputPath); long headerLength; try (final CountingOutputStream out = new CountingOutputStream(Files.newOutputStream(outputPath))) { if (header != null) { new SAMOutputPreparer().prepareForRecords(out, samOutputFormat, header); } headerLength = out.getCount(); mergeInto(parts, out); writeTerminatorBlock(out, samOutputFormat); } long fileLength = Files.size(outputPath); final Path outputSplittingBaiPath = outputPath.resolveSibling( outputPath.getFileName() + SplittingBAMIndexer.OUTPUT_FILE_EXTENSION); Files.deleteIfExists(outputSplittingBaiPath); try (final OutputStream out = Files.newOutputStream(outputSplittingBaiPath)) { mergeSplittingBaiFiles(out, partPath, headerLength, fileLength); } catch (IOException e) { deleteRecursive(outputSplittingBaiPath); throw e; } deleteRecursive(partPath); }