private void blockCompressAndIndex(String in,String bgzfOut,boolean deleteOnExit) throws IOException {
  File inFile=new File(in);
  File outFile=new File(bgzfOut);
  LineIterator lin=IOUtils.openURIForLineIterator(inFile.getAbsolutePath());
  BlockCompressedOutputStream writer=new BlockCompressedOutputStream(outFile);
  long filePosition=writer.getFilePointer();
  TabixIndexCreator indexCreator=new TabixIndexCreator(TabixFormat.BED);
  BedLineCodec bedCodec=new BedLineCodec();
  while (lin.hasNext()) {
    String line=lin.next();
    BedLine bed=bedCodec.decode(line);
    if (bed == null)     continue;
    writer.write(line.getBytes());
    writer.write('\n');
    indexCreator.addFeature(bed,filePosition);
    filePosition=writer.getFilePointer();
  }
  writer.flush();
  File tbi=new File(bgzfOut + TabixUtils.STANDARD_INDEX_EXTENSION);
  if (tbi.exists() && tbi.isFile()) {
    writer.close();
    throw new RuntimeException("Index file exists: " + tbi);
  }
  Index index=indexCreator.finalizeIndex(writer.getFilePointer());
  index.writeBasedOnFeatureFile(outFile);
  writer.close();
  if (deleteOnExit) {
    outFile.deleteOnExit();
    File idx=new File(outFile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION);
    idx.deleteOnExit();
  }
}

private void blockCompressAndIndex ( String in , String bgzfOut , boolean deleteOnExit ) throws IOException { File inFile = new File ( in ) ; File outFile = new File ( bgzfOut ) ; LineIterator lin = IOUtils . openURIForLineIterator ( inFile . getAbsolutePath ( ) ) ; BlockCompressedOutputStream writer = new BlockCompressedOutputStream ( outFile ) ; long filePosition = writer . getFilePointer ( ) ; TabixIndexCreator indexCreator = new TabixIndexCreator ( TabixFormat . BED ) ; BedLineCodec bedCodec = new BedLineCodec ( ) ; while ( lin . hasNext ( ) ) { String line = lin . next ( ) ; BedLine bed = bedCodec . decode ( line ) ; if ( bed == null ) continue ; writer . write ( line . getBytes ( ) ) ; writer . write ( '\n' ) ; indexCreator . addFeature ( bed , filePosition ) ; filePosition = writer . getFilePointer ( ) ; } writer . flush ( ) ; File tbi = new File ( bgzfOut + TabixUtils . STANDARD_INDEX_EXTENSION ) ; if ( tbi . exists ( ) && tbi . isFile ( ) ) { writer . close ( ) ; throw new RuntimeException ( "Index file exists: " + tbi ) ; } Index index = indexCreator . finalizeIndex ( writer . getFilePointer ( ) ) ; index . writeBasedOnFeatureFile ( outFile ) ; writer . close ( ) ; if ( deleteOnExit ) { outFile . deleteOnExit ( ) ; File idx = new File ( outFile . getAbsolutePath ( ) + TabixUtils . STANDARD_INDEX_EXTENSION ) ; idx . deleteOnExit ( ) ; } }
block compress input file and create associated tabix index . newly created file and index are deleted on exit if deleteonexit true .
