Example usage for java.io PrintStream PrintStream

List of usage examples for java.io PrintStream PrintStream

Introduction

In this page you can find the example usage for java.io PrintStream PrintStream.

Prototype

public PrintStream(File file) throws FileNotFoundException 

Source Link

Document

Creates a new print stream, without automatic line flushing, with the specified file.

Usage

From source file:co.cask.cdap.logging.appender.file.TestFileLogging.java

@BeforeClass
public static void setUpContext() throws Exception {
    dsFramework = new InMemoryDatasetFramework(new InMemoryDefinitionRegistryFactory());
    dsFramework.addModule("table", new InMemoryOrderedTableModule());

    LoggingContextAccessor//from  w  w w . j a v  a 2 s  .  c om
            .setLoggingContext(new FlowletLoggingContext("TFL_ACCT_1", "APP_1", "FLOW_1", "FLOWLET_1"));
    logBaseDir = "/tmp/log_files_" + new Random(System.currentTimeMillis()).nextLong();

    CConfiguration cConf = CConfiguration.create();
    cConf.set(LoggingConfiguration.LOG_BASE_DIR, logBaseDir);
    cConf.setInt(LoggingConfiguration.LOG_MAX_FILE_SIZE_BYTES, 20 * 1024);

    Configuration conf = HBaseConfiguration.create();
    cConf.copyTxProperties(conf);
    TransactionManager txManager = new TransactionManager(conf);
    txManager.startAndWait();
    txClient = new InMemoryTxSystemClient(txManager);

    LogAppender appender = new AsyncLogAppender(
            new FileLogAppender(cConf, dsFramework, txClient, new LocalLocationFactory()));
    new LogAppenderInitializer(appender).initialize("TestFileLogging");

    Logger logger = LoggerFactory.getLogger("TestFileLogging");
    for (int i = 0; i < 60; ++i) {
        Exception e1 = new Exception("Test Exception1");
        Exception e2 = new Exception("Test Exception2", e1);
        logger.warn("Test log message " + i + " {} {}", "arg1", "arg2", e2);
    }

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    StatusPrinter.setPrintStream(new PrintStream(bos));
    StatusPrinter.print((LoggerContext) LoggerFactory.getILoggerFactory());
    System.out.println(bos.toString());

    appender.stop();
}

From source file:edu.cornell.med.icb.goby.modes.ReadSetToTextMode.java

/**
 * Display the alignments as text files.
 *
 * @throws java.io.IOException error reading / writing
 *//*from w  w w  . jav  a2 s  . co m*/
@Override
public void execute() throws IOException {
    PrintStream stream = null;
    try {
        stream = outputFilename == null ? System.out : new PrintStream(new FileOutputStream(outputFilename));
        switch (outputFormat) {
        case PLAIN:
            stream.printf("queryIndex\tmultiplicity%n");
            break;
        default:
            throw new IllegalArgumentException("Unknown output format: " + outputFormat);
        }

        for (final String basename : basenames) {
            final ReadSet set = new ReadSet();
            set.load(basename, suffix);

            for (int queryIndex = 0; queryIndex <= set.getMaxReadIndex(); queryIndex++) {
                final int multiplicity = set.getMultiplicity(queryIndex);
                stream.printf("%d\t%d%n", queryIndex,

                        multiplicity);
            }
        }
    } finally {
        if (stream != System.out) {
            IOUtils.closeQuietly(stream);
        }
    }
}