Example usage for java.lang System setOut

List of usage examples for java.lang System setOut

Introduction

In this page you can find the example usage for java.lang System setOut.

Prototype

public static void setOut(PrintStream out) 

Source Link

Document

Reassigns the "standard" output stream.

Usage

From source file:functionaltests.TagCommandsFunctTest.java

@Test
public void testListJobTaskIdsUnknownJob() throws Exception {
    typeLine("listtasks(" + NOT_EXISTENT_JOBID + ", 'unknownTag')");

    runCli();//  w  ww  .j  a v a 2 s  .co m

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testListJobTaskIdsUnknownJob:");
    System.out.println(out);
    assertTrue(out.contains("error"));
    assertTrue(!out.contains("T1#1"));
    assertTrue(!out.contains("Print1#1"));
    assertTrue(!out.contains("Print2#1"));
    assertTrue(!out.contains("T2#1"));
    assertTrue(!out.contains("T1#2"));
    assertTrue(!out.contains("Print1#2"));
    assertTrue(!out.contains("Print2#2"));
    assertTrue(!out.contains("T2#2"));
}

From source file:net.sourceforge.seqware.pipeline.plugins.BatchMetadataInjectionTest.java

/**
 * Tests to see that the json was imported correctly
 *
 * @throws IOException/*from  ww  w  .  ja  va  2  s . co  m*/
 */

@Test
public void testImportJsonSequencerRun() throws IOException {
    System.out.println("Testing if importing a json file works");

    String[] bmiparams = { "--import-json-sequencer-run", inputJsonCorrect };

    PrintStream old = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));

    //Runs the Batch Metadata injection with the input json and importing a json run
    BatchMetadataInjection.main(bmiparams);
    String output = baos.toString();

    //Gets the IUSs from the stdout
    getStdOut(output);
    runFileLinkerPlugin(createFileLinkerFile(iusSwids), wfaccession);
    getData();
    writeToObjects();

    System.setOut(old);
    Assert.assertTrue("The JSON doesn't match", equals(originalObject, runInfo, inputJsonCorrect));
    System.out.println("The JSON matches");

}

From source file:ape_test.CLITest.java

public void testMissingArgument() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);

    String[] arg = new String[1];
    arg[0] = "R";
    Main.main(arg);/*w  w w . j a  v  a  2  s.  co  m*/
    System.setOut(originalOut);
    assertNotSame("", os.toString());
}

From source file:org.apache.hadoop.hive.ql.io.orc.TestFixAcidKeyIndex.java

void runIndexCheck(Path orcFile, File outFile) throws Exception {
    // Run with --check-index and save the output to file so it can be checked.
    PrintStream origOut = System.out;
    FileOutputStream myOut = new FileOutputStream(outFile);

    System.setOut(new PrintStream(myOut));
    String[] checkArgs = new String[] { "--check-only", orcFile.toString() };
    FixAcidKeyIndex.main(checkArgs);//from   w  w  w.j  a v a 2  s  .  c o  m
    System.out.flush();
    System.setOut(origOut);
}

From source file:de.peran.dependency.ChangedTestClassesHandler.java

private void updateDependenciesOnce(final String testClassName, final String testMethodName,
        final File parent) {
    LOG.debug("Parent: " + parent);
    final File[] listFiles = parent.listFiles(new FileFilter() {
        @Override//w  w  w  .j a v  a2 s .c o m
        public boolean accept(final File pathname) {
            return pathname.getName().matches("[0-9]*");
        }
    });
    LOG.debug("Kieker-Dateien: {}", listFiles.length);
    final File kiekerAllFolder = listFiles[0];
    LOG.debug("Analysiere Ordner: {} {}", kiekerAllFolder.getAbsolutePath(), testMethodName);
    final File kiekerNextFolder = new File(kiekerAllFolder, testMethodName);
    final File kiekerResultFolder = kiekerNextFolder.listFiles()[0];
    LOG.debug("Test: " + testMethodName);

    final PrintStream out = System.out;
    final PrintStream err = System.err;

    final File kiekerOutputFile = new File(projectFolder.getParent(), "ausgabe_kieker.txt");
    Map<String, Set<String>> calledClasses = null;
    try {
        System.setOut(new PrintStream(kiekerOutputFile));
        System.setErr(new PrintStream(kiekerOutputFile));
        calledClasses = new CalledMethodLoader(kiekerResultFolder).getCalledMethods();
        for (final Iterator<String> iterator = calledClasses.keySet().iterator(); iterator.hasNext();) {
            final String clazz = iterator.next();
            final String onlyClass = clazz.substring(clazz.lastIndexOf(".") + 1);
            final Collection<File> files = FileUtils.listFiles(projectFolder,
                    new WildcardFileFilter(onlyClass + "*"), TrueFileFilter.INSTANCE);
            if (files.size() == 0) {
                iterator.remove();
            }
        }
    } catch (final FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        System.setOut(out);
        System.setErr(err);
    }

    LOG.debug("Test: {} {}", testClassName, testMethodName);
    LOG.debug("Kieker: {} Dependencies: {}", kiekerResultFolder.getAbsolutePath(), calledClasses.size());
    final Map<String, Set<String>> dependencies = this.dependencies
            .getDependenciesForTest(testClassName + "." + testMethodName);
    dependencies.putAll(calledClasses);
}

From source file:eu.scape_project.tika_identify.TikaIdentification.java

public void startApplication() throws IOException {
    long startClock = System.currentTimeMillis();
    File dir = new File(appConfig.getInputStr());
    if (!dir.isDirectory()) {
        throw new IllegalArgumentException("Input is not a directory: " + appConfig.getInputStr());
    }/*ww w  . j av a2 s . co  m*/
    PrintStream pout = null;
    String outputPathStr = appConfig.getOutputStr();
    if (outputPathStr != null) {
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(outputPathStr, true);
            pout = new PrintStream(fos);
            System.setOut(pout);
        } catch (FileNotFoundException ex) {
            LOG.error("File not found error", ex);
        }
    }
    this.processFiles(new File(appConfig.getInputStr()));
    if (pout != null) {
        pout.close();
    }
    long elapsedTimeMillis = System.currentTimeMillis() - startClock;
    LOG.info("Identification finished after " + elapsedTimeMillis + " milliseconds");
}

From source file:org.languagetool.commandline.MainTest.java

@Before
public void setUp() throws Exception {
    super.setUp();
    this.stdout = System.out;
    this.stderr = System.err;
    this.out = new ByteArrayOutputStream();
    this.err = new ByteArrayOutputStream();
    System.setOut(new PrintStream(this.out));
    System.setErr(new PrintStream(this.err));
}

From source file:eu.scape_project.cdx_creator.CDXCreationTask.java

public void createIndex() {
    FileInputStream fileInputStream = null;
    ArchiveReader reader = null;/*from   w w  w. j  a v a 2 s .c o  m*/
    FileOutputStream outputStream = null;
    try {
        fileInputStream = new FileInputStream(archiveFile);
        reader = ArchiveReaderFactory.getReader(fileInputStream, this.archiveFileName);
        reader.setComputePayloadDigest(config.isCreatePayloadDigest());
        List<CdxArchiveRecord> cdxArchRecords = new ArrayList<CdxArchiveRecord>();
        while (reader.hasNext()) {
            ArchiveRecord archRec = (ArchiveRecord) reader.next();
            CdxArchiveRecord cdxArchRec = CdxArchiveRecord.fromArchiveRecord(archRec);
            cdxArchRec.setContainerFileName(archiveFileName);
            cdxArchRec.setContainerLengthStr(Long.toString(archiveFile.length()));
            cdxArchRecords.add(cdxArchRec);
        }

        CsvMapper mapper = new CsvMapper();
        mapper.setDateFormat(GMTGTechDateFormat);

        String cdxfileCsColumns = config.getCdxfileCsColumns();
        List<String> cdxfileCsColumnsList = Arrays.asList(cdxfileCsColumns.split("\\s*,\\s*"));
        String[] cdxfileCsColumnsArray = cdxfileCsColumnsList.toArray(new String[cdxfileCsColumnsList.size()]);

        CsvSchema.Builder builder = CsvSchema.builder();
        for (String cdxField : cdxfileCsColumnsList) {
            builder.addColumn(cdxField);
        }
        builder.setColumnSeparator(' ');
        CsvSchema schema = builder.build();
        schema = schema.withoutQuoteChar();

        SimpleFilterProvider filterProvider = new SimpleFilterProvider().addFilter("cdxfields",
                FilterExceptFilter.filterOutAllExcept(cdxfileCsColumnsArray));

        ObjectWriter cdxArchRecordsWriter = mapper.writer(filterProvider).withSchema(schema);

        PrintStream pout = null;
        String outputPathStr = config.getOutputStr();
        if (outputPathStr != null) {
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(outputPathStr, true);
                pout = new PrintStream(fos);
                System.setOut(pout);
            } catch (FileNotFoundException ex) {
                LOG.error("File not found error", ex);
            }
        }
        System.out.println(" " + config.getCdxfileCsHeader());

        cdxArchRecordsWriter.writeValue(System.out, cdxArchRecords);

        if (pout != null) {
            pout.close();
        }

    } catch (FileNotFoundException ex) {
        LOG.error("File not found error", ex);
    } catch (IOException ex) {
        LOG.error("I/O Error", ex);
    } finally {
        try {
            if (fileInputStream != null) {
                fileInputStream.close();
            }

            if (outputStream != null) {
                outputStream.close();
            }

        } catch (IOException ex) {
            LOG.error("I/O Error", ex);
        }
    }
}

From source file:com.crawljax.plugins.aji.executiontracer.JSExecutionTracer.java

@Override
public void postCrawling(CrawlSession session) {
    try {/*  ww  w. j a v  a2  s.  c  o m*/
        PrintStream output = new PrintStream(getOutputFolder() + getAssertionFilename());

        /* save the current System.out for later usage */
        PrintStream oldOut = System.out;
        /* redirect it to the file */
        System.setOut(output);

        /* don't print all the useless stuff */
        Daikon.dkconfig_quiet = true;
        Daikon.noversion_output = true;

        List<String> arguments = allTraceFiles();

        /*
         * TODO: Frank, fix this hack (it is done because of Daikon calling cleanup before init)
         */
        arguments.add("-o");
        arguments.add(getOutputFolder() + "daikon.inv.gz");
        arguments.add("--format");
        arguments.add("javascript");
        arguments.add("--config_option");
        arguments.add("daikon.FileIO.unmatched_procedure_entries_quiet=true");
        arguments.add("--config_option");
        arguments.add("daikon.FileIO.ignore_missing_enter=true");

        /* start daikon */
        Daikon.mainHelper(arguments.toArray(new String[0]));

        /* Restore the old system.out */
        System.setOut(oldOut);

        /* close the output file */
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.jwebsocket.ui.TestDialog.java

public void initializeLogs() {
    PrintStream lPrintStream;/*from   w  ww.  j  a  v a 2s .  c  om*/
    OutputStreamConsole lConsole = new OutputStreamConsole(txaLog);
    lPrintStream = new PrintStream(lConsole);
    System.setOut(lPrintStream);
    System.setErr(lPrintStream);
}