All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jruby.runtime.profile.ProfileOutput Maven / Gradle / Ivy

There is a newer version: 0.8.14
Show newest version
package org.jruby.runtime.profile;


import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FileNotFoundException;


public class ProfileOutput {
  private final PrintStream stream;

  private boolean headerPrinted = false;

  
  public ProfileOutput(PrintStream out) {
    this.stream = out;
  }

  public ProfileOutput(File out) throws FileNotFoundException {
    this.stream = new PrintStream(new FileOutputStream(out));
  }

  public void printProfile(ProfilePrinter printer) {
    if (headerPrinted) {
      printer.printProfile(stream, false);
    } else {
      printer.printHeader(stream);
      printer.printProfile(stream, true);
      headerPrinted = true;
      footerAndCleanupOnShutdown(printer);
    }
  }

  private void footerAndCleanupOnShutdown(final ProfilePrinter printer) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
      public void run() {
        printer.printFooter(stream);
        stream.close();
      }
    });
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy