public OutputStream createStreamsAndStartThreads(int numberReferences,boolean expectHeader,boolean terminateBlockGzip) throws IOException {
  if (mOutputStream == null) {
    final boolean bam=mIndexerFactory == null;
    final boolean gzonly=!bam && mCompress;
    if (mCreateIndexIfPossible && mCompress) {
      final PipedInputStream pipeToIndexIn=new PipedInputStream();
      final PipedOutputStream pipeToIndexOut=new PipedOutputStream(pipeToIndexIn);
      mOutputStream=FileUtils.createTeedOutputStream(mOutputFile,pipeToIndexOut,gzonly,false,terminateBlockGzip);
      final OutputStream indexOutputStream;
      if (bam) {
        indexOutputStream=FileUtils.createOutputStream(BamIndexer.indexFileName(mOutputFile));
      }
 else {
        assert mCompress;
        indexOutputStream=FileUtils.createOutputStream(TabixIndexer.indexFileName(mOutputFile));
      }
      final IndexRunner indexRunner=new IndexRunner(pipeToIndexIn,indexOutputStream,mIndexerFactory,expectHeader,numberReferences,mOutputFile.toString());
      mProxy=new IORunnableProxy(indexRunner);
      mIndexThread=new Thread(mProxy);
      mIndexThread.start();
    }
 else {
      mOutputStream=FileUtils.createOutputStream(mOutputFile,gzonly,false,true);
    }
  }
  return mOutputStream;
}

public OutputStream createStreamsAndStartThreads ( int numberReferences , boolean expectHeader , boolean terminateBlockGzip ) throws IOException { if ( mOutputStream == null ) { final boolean bam = mIndexerFactory == null ; final boolean gzonly = ! bam && mCompress ; if ( mCreateIndexIfPossible && mCompress ) { final PipedInputStream pipeToIndexIn = new PipedInputStream ( ) ; final PipedOutputStream pipeToIndexOut = new PipedOutputStream ( pipeToIndexIn ) ; mOutputStream = FileUtils . createTeedOutputStream ( mOutputFile , pipeToIndexOut , gzonly , false , terminateBlockGzip ) ; final OutputStream indexOutputStream ; if ( bam ) { indexOutputStream = FileUtils . createOutputStream ( BamIndexer . indexFileName ( mOutputFile ) ) ; } else { assert mCompress ; indexOutputStream = FileUtils . createOutputStream ( TabixIndexer . indexFileName ( mOutputFile ) ) ; } final IndexRunner indexRunner = new IndexRunner ( pipeToIndexIn , indexOutputStream , mIndexerFactory , expectHeader , numberReferences , mOutputFile . toString ( ) ) ; mProxy = new IORunnableProxy ( indexRunner ) ; mIndexThread = new Thread ( mProxy ) ; mIndexThread . start ( ) ; } else { mOutputStream = FileUtils . createOutputStream ( mOutputFile , gzonly , false , true ) ; } } return mOutputStream ; }
create the output stream
