code: public static void index(
  			final InputStream rawIn, final OutputStream out, final long inputSize,
  			final int granularity)
  		throws IOException
  	{
  		final BlockCompressedInputStream in =
  			new BlockCompressedInputStream(rawIn);
  
  		final ByteBuffer byteBuffer = ByteBuffer.allocate(8); // Enough to fit a long
  		final LongBuffer lb =
  			byteBuffer.order(ByteOrder.BIG_ENDIAN).asLongBuffer();
  
  		skipToAlignmentList(byteBuffer, in);
  
  		// Always write the first one to make sure it's not skipped
  		lb.put(0, in.getFilePointer());
  		out.write(byteBuffer.array());
  
  		long prevPrint = in.getFilePointer() >> 16;
  
  		for (int i = 0;;) {
  			final PtrSkipPair pair = readAlignment(byteBuffer, in);
  			if (pair == null)
  				break;
  
  			if (++i == granularity) {
  				i = 0;
  				lb.put(0, pair.ptr);
  				out.write(byteBuffer.array());
  
  				final long filePos = pair.ptr >> 16;
  				if (filePos - prevPrint >= PRINT_EVERY) {
  					System.out.print("-");
  					prevPrint = filePos;
  				}
  			}
  			fullySkip(in, pair.skip);
  		}
  		lb.put(0, inputSize << 16);
  		out.write(byteBuffer.array());
  		out.close();
  		in.close();
  	}
docs: Perform indexing on the given BAM file, at the granularity level specified.