code: public static void printWigFormatCoverage(RegionCoverage regionCoverage, int span, boolean header, PrintWriter writer) {
          // sanity check
          if (span < 1) {
              span = 1;
          }
          if (header) {
              writer.println("fixedStep chrom=" + regionCoverage.getChromosome() + " start=1 step=1 span=" + span);
          }
          float[] values = regionCoverage.getValues();
          if (span == 1) {
              for (int i = 0; i < values.length; i++) {
                  writer.println(values[i]);
              }
          } else {
              int counter = 0;
              int sum = 0;
              for (int i = 0; i < values.length; i++) {
                  counter++;
                  sum += values[i];
                  if (counter == span) {
                      writer.println(sum / counter);
                      counter = 0;
                      sum = 0;
                  }
              }
              if (counter > 0) {
                  writer.println(sum / counter);
              }
          }
      }
docs: Write in wig file format the coverage for the region given. It uses fixedStep with step equals to 1.
  
  @param regionCoverage    Region containing the coverage values
  @param span              Span (to group coverage contiguous values in a mean coverage)
  @param header            Flag, to write a header line (assuming fixedStep, and start=1 and step=1)
  @param writer            File writer