Example usage for java.lang System setErr

List of usage examples for java.lang System setErr

Introduction

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

Prototype

public static void setErr(PrintStream err) 

Source Link

Document

Reassigns the "standard" error output stream.

Usage

From source file:com.github.jessemull.microflexbiginteger.stat.MeanWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *///from   w ww  .  j  a  v a 2 s  .c o m
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        Plate plate = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        Plate plateIndices = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue, lengthIndices,
                "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        weights[i] = random.nextDouble();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        weightsIndices[i] = random.nextDouble();
    }
}

From source file:de.undercouch.citeproc.tool.ShellCommand.java

@Override
public int doRun(String[] remainingArgs, InputReader in, PrintWriter out)
        throws OptionParserException, IOException {
    //prepare console
    final ConsoleReader reader = new ConsoleReader();
    reader.setPrompt("> ");
    reader.addCompleter(new ShellCommandCompleter(EXCLUDED_COMMANDS));
    FileHistory history = new FileHistory(
            new File(CSLToolContext.current().getConfigDir(), "shell_history.txt"));
    reader.setHistory(history);/*w  w w. j  av a 2s .  c  o  m*/

    //enable colored error stream for ANSI terminals
    if (reader.getTerminal().isAnsiSupported()) {
        OutputStream errout = new ErrorOutputStream(reader.getTerminal().wrapOutIfNeeded(System.out));
        System.setErr(new PrintStream(errout, false, ((OutputStreamWriter) reader.getOutput()).getEncoding()));
    }

    PrintWriter cout = new PrintWriter(reader.getOutput(), true);

    //print welcome message
    cout.println("Welcome to " + CSLToolContext.current().getToolName() + " " + CSLTool.getVersion());
    cout.println();
    cout.println("Type `help' for a list of commands and `help " + "<command>' for information");
    cout.println("on a specific command. Type `quit' to exit " + CSLToolContext.current().getToolName() + ".");
    cout.println();

    String line;
    ShellContext.enter();
    try {
        line = mainLoop(reader, cout);
    } finally {
        ShellContext.exit();

        //make sure we save the history before we exit
        history.flush();
    }

    //print Goodbye message
    if (line == null) {
        //user pressed Ctrl+D
        cout.println();
    }
    cout.println("Bye!");

    return 0;
}

From source file:org.apache.sysml.test.integration.functions.misc.SetWorkingDirTest.java

/**
 * /*from   ww  w. jav a  2 s .  c om*/
 * @param testName
 * @param fileMissingTest
 * @param scriptType
 */
private void runTest(String testName, boolean fileMissingTest, ScriptType scriptType) {

    // construct source filenames of dml scripts
    String dir = SCRIPT_DIR + TEST_DIR;
    String nameCall = testName + "." + scriptType.lowerCase();
    String nameLib = TEST_NAME0 + "." + scriptType.lowerCase();

    PrintStream originalStdErr = System.err;

    try {
        ByteArrayOutputStream baos = null;
        if (fileMissingTest) {
            baos = new ByteArrayOutputStream();
            PrintStream newStdErr = new PrintStream(baos);
            System.setErr(newStdErr);
        }

        // copy dml/pydml scripts to current dir
        FileUtils.copyFile(new File(dir + nameCall), new File(nameCall));
        if (!fileMissingTest)
            FileUtils.copyFile(new File(dir + nameLib), new File(nameLib));

        // setup test configuration
        TestConfiguration config = getTestConfiguration(testName);
        fullDMLScriptName = nameCall;
        if (scriptType == ScriptType.PYDML) {
            programArgs = new String[] { "-python" };
        } else {
            programArgs = new String[] {};
        }
        loadTestConfiguration(config);

        // run tests
        runTest(true, false, null, -1);

        if (fileMissingTest) {
            String stdErrString = baos.toString();
            if (stdErrString == null) {
                fail("Standard error string is null"); // shouldn't happen
            } else if (!stdErrString.contains("Cannot find file")) {
                // the error message should contain "Cannot find file" if file is missing
                fail("Should not be able to find file: " + nameLib);
            }
            if (stdErrString != null) {
                originalStdErr.println(stdErrString); // send standard err string to console
            }
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        System.setErr(originalStdErr);
        // delete dml/pydml scripts from current dir (see above)
        LocalFileUtils.deleteFileIfExists(nameCall);
        if (!fileMissingTest)
            LocalFileUtils.deleteFileIfExists(nameLib);
    }
}

From source file:org.apache.hadoop.hive.metastore.tools.TestSchemaToolCatalogOps.java

@AfterClass
public static void removeDb() throws Exception {
    File metaStoreDir = new File(testMetastoreDB);
    if (metaStoreDir.exists()) {
        FileUtils.forceDeleteOnExit(metaStoreDir);
    }/*  w ww .  j  a  v  a  2 s.  c  o m*/
    System.setOut(outStream);
    System.setErr(errStream);
}

From source file:org.pentaho.di.kitchen.KitchenIT.java

@Test
public void testArchivedJobsExecution() throws Exception {
    String file = this.getClass().getResource("test-kjb.zip").getFile();
    String[] args = new String[] { "/file:zip:file://" + file + "!Job.kjb" };
    oldOut = System.out;/*  w  w w.  j  a va2 s.co m*/
    oldErr = System.err;
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
    try {
        Kitchen.main(args);
    } catch (SecurityException e) {
        System.setOut(oldOut);
        System.setErr(oldErr);
        System.out.println(outContent);
        assertFalse(outContent.toString().contains("result=[false]"));
        assertFalse(outContent.toString().contains("ERROR"));
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MeanWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *//*from   w w w.  j a v a 2 s.co  m*/
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        Plate plate = RandomUtil.randomPlateBigDecimal(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        Plate plateIndices = RandomUtil.randomPlateBigDecimal(rows, columns, minValue, maxValue, lengthIndices,
                "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        double randomDouble = random.nextDouble();
        weights[i] = new BigDecimal(randomDouble + "", contextWeights).doubleValue();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        double randomDouble = random.nextDouble();
        weightsIndices[i] = new BigDecimal(randomDouble + "", contextWeights).doubleValue();
    }
}

From source file:org.apache.solr.hadoop.MapReduceIndexerToolArgumentParserTest.java

@Before
public void setUp() throws Exception {
    super.setUp();
    AbstractZkTestCase.SOLRHOME = solrHomeDirectory;
    FileUtils.copyDirectory(MINIMR_INSTANCE_DIR, solrHomeDirectory);

    conf = new Configuration();
    parser = new MapReduceIndexerTool.MyArgumentParser();
    opts = new MapReduceIndexerTool.Options();
    oldSystemOut = System.out;/*from   www  .j  a v  a  2 s. c o m*/
    bout = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bout, true, "UTF-8"));
    oldSystemErr = System.err;
    berr = new ByteArrayOutputStream();
    System.setErr(new PrintStream(berr, true, "UTF-8"));
}

From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java

private static void initLog() throws Exception {
    String logDir = ConfigManager.getInstance().get(null, "output_dir", ".");
    File logDirFile = new File(logDir);
    if (!logDirFile.exists()) {
        logDirFile.mkdirs();/*from w  w w  .ja v  a2 s  . c  o m*/
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss.SSS");
    String date = df.format(new Date());

    String stdoutLogFile = new File(logDir, "stdout_" + date + ".log").getAbsolutePath();
    LogOutputStream stdout = new LogOutputStream(stdoutLogFile, System.out);
    System.setOut(new PrintStream(stdout, true));

    String stderrLogFile = new File(logDir, "stderr_" + date + ".log").getAbsolutePath();
    LogOutputStream stderr = new LogOutputStream(stderrLogFile, System.err);
    System.setErr(new PrintStream(stderr, true));

}

From source file:com.complexible.stardog.ext.spring.TestDataSourceFactory.java

/**
 * TODO: perhaps not load 10k triples for each JUnit test
 * @throws java.lang.Exception// ww w  . j  a v  a2s. c  om
 */
@Before
public void setUp() throws Exception {
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
    assertNotNull(dataSource);
    SnarlTemplate tmp = new SnarlTemplate();
    tmp.setDataSource(dataSource);
    DataImporter importer = new DataImporter();
    importer.setSnarlTemplate(tmp);
    importer.inputFile(RDFFormat.N3, applicationContext.getResource("classpath:sp2b_10k.n3"));

}

From source file:com.github.jessemull.microflex.stat.statbiginteger.MeanBigIntegerWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *///from  www  .java2  s . c om
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        PlateBigInteger plate = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        PlateBigInteger plateIndices = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue,
                lengthIndices, "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        weights[i] = random.nextDouble();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        weightsIndices[i] = random.nextDouble();
    }
}