code: public static void createCoverageWigFile(Path bamPath, Path coveragePath, int span) throws IOException, AlignmentCoverageException {
          SAMFileHeader fileHeader = BamUtils.getFileHeader(bamPath);
  
          AlignmentOptions options = new AlignmentOptions();
          options.setContained(false);
  
          BamManager alignmentManager = new BamManager(bamPath);
          Iterator<SAMSequenceRecord> iterator = fileHeader.getSequenceDictionary().getSequences().iterator();
          PrintWriter writer = new PrintWriter(coveragePath.toFile());
          // chunkSize = 100000 (too small, it takes loooooong...)
          int chunkSize = Math.max(span, 200000 / span * span);
          while (iterator.hasNext()) {
              SAMSequenceRecord next = iterator.next();
              for (int i = 0; i < next.getSequenceLength(); i += chunkSize) {
                  Region region = new Region(next.getSequenceName(), i + 1, Math.min(i + chunkSize, next.getSequenceLength()));
                  RegionCoverage regionCoverage = alignmentManager.coverage(region, null, options);
                  printWigFormatCoverage(regionCoverage, span, (i == 0), writer);
              }
          }
          writer.close();
      }
docs: Utility to compute the coverage from a BAM file, and create a wig format file with the coverage values according
  to a window size (i.e., span in wig format specification).
  
  @param bamPath           BAM file
  @param coveragePath      Wig file name where to save coverage values
  @param span              Span (to group coverage contiguous values in a mean coverage)
  @throws IOException