format/src/main/java/com/github/sadikovi/riff/FileWriter.java
/**
   * Finish writes.
   * All buffers are flushed at the end of this operation and streams are closed.
   * @throws IOException
   */
Finish writes.
All buffers are flushed at the end of this operation and streams are closed.
Finish writes . All buffers are flushed at the end of this operation and streams are closed .
public void finishWrite() throws IOException {
    if (!writePrepared) throw new IOException("Writer is not prepared");
    if (writeFinished) return;
    try {
      stripeStream.flush();
      StripeInformation stripeInfo =
        new StripeInformation(stripe, currentOffset, stripeStats, stripeFilters);
      stripe.flush(outputStream);
      LOG.debug("Finished writing stripe {}, records={}", stripeInfo,
        numRowsInStripe - stripeCurrentRecords);
      totalRecords += numRowsInStripe - stripeCurrentRecords;
      stripes.add(stripeInfo);
      stripeStream.close();
      stripe = null;
      stripeStream = null;
      stripeStats = null;
      LOG.debug("Merge stripe statistics");
      Statistics[] fileStats = createStatistics(td);
      for (StripeInformation info : stripes) {
        if (info.hasStatistics()) {
          for (int i = 0; i < fileStats.length; i++) {
            fileStats[i].merge(info.getStatistics()[i]);
          }
        }
      }
      LOG.debug("Write file footer");
      FileFooter fileFooter = FileFooter.create(fileStats, totalRecords, stripes);
      fileFooter.writeTo(outputStream);
    } finally {
      if (outputStream != null) {
        outputStream.close();
      }
      if (codec != null) {
        codec.close();
      }
    }
    LOG.info("Finished writing file {}", filePath);
    writeFinished = true;
  }
public void finishWrite ( ) throws IOException { if ( ! writePrepared ) throw new IOException ( "Writer is not prepared" ) ; if ( writeFinished ) return ; try { stripeStream . flush ( ) ; StripeInformation stripeInfo = new StripeInformation ( stripe , currentOffset , stripeStats , stripeFilters ) ; stripe . flush ( outputStream ) ; LOG . debug ( "Finished writing stripe {}, records={}" , stripeInfo , numRowsInStripe - stripeCurrentRecords ) ; totalRecords += numRowsInStripe - stripeCurrentRecords ; stripes . add ( stripeInfo ) ; stripeStream . close ( ) ; stripe = null ; stripeStream = null ; stripeStats = null ; LOG . debug ( "Merge stripe statistics" ) ; Statistics [ ] fileStats = createStatistics ( td ) ; for ( StripeInformation info : stripes ) { if ( info . hasStatistics ( ) ) { for ( int i = 0 ; i < fileStats . length ; i ++ ) { fileStats [ i ] . merge ( info . getStatistics ( ) [ i ] ) ; } } } LOG . debug ( "Write file footer" ) ; FileFooter fileFooter = FileFooter . create ( fileStats , totalRecords , stripes ) ; fileFooter . writeTo ( outputStream ) ; } finally { if ( outputStream != null ) { outputStream . close ( ) ; } if ( codec != null ) { codec . close ( ) ; } } LOG . info ( "Finished writing file {}" , filePath ) ; writeFinished = true ; }
Finish writes.
Finish writes .
// flush the last stripe into output stream // update total records with delta // combine all statistics for a file // close file stream // release codec resources