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:org.apache.taverna.scufl2.wfdesc.TestConvertToWfdesc.java

@After
public void restoreStd() {
    System.setIn(origIn);
    System.setOut(origOut);
    System.setErr(origErr);
}

From source file:org.bonitasoft.engine.api.HTTPServerAPITest.java

@Test(expected = ServerWrappedException.class)
public void invokeMethodCatchUndeclaredThrowableException() throws Exception {
    final PrintStream printStream = System.err;
    final ByteArrayOutputStream myOut = new ByteArrayOutputStream();
    System.setErr(new PrintStream(myOut));
    final Logger logger = Logger.getLogger(HTTPServerAPI.class.getName());
    logger.setLevel(Level.FINE);//  w  ww. j a v a2 s.c  o  m
    final ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.FINE);
    logger.addHandler(ch);

    try {
        final Map<String, Serializable> options = new HashMap<String, Serializable>();
        final String apiInterfaceName = "apiInterfaceName";
        final String methodName = "methodName";
        final List<String> classNameParameters = new ArrayList<String>();
        final Object[] parametersValues = null;

        final HTTPServerAPI httpServerAPI = mock(HTTPServerAPI.class);
        final String response = "response";
        doReturn(response).when(httpServerAPI, "executeHttpPost", eq(options), eq(apiInterfaceName),
                eq(methodName), eq(classNameParameters), eq(parametersValues), Matchers.any(XStream.class));
        doThrow(new UndeclaredThrowableException(new BonitaException("Bonita exception"), "Exception plop"))
                .when(httpServerAPI, "checkInvokeMethodReturn", eq(response), Matchers.any(XStream.class));

        // Let's call it for real:
        doCallRealMethod().when(httpServerAPI).invokeMethod(options, apiInterfaceName, methodName,
                classNameParameters, parametersValues);
        httpServerAPI.invokeMethod(options, apiInterfaceName, methodName, classNameParameters,
                parametersValues);
    } finally {
        System.setErr(printStream);
        final String logs = myOut.toString();
        assertTrue("should have written in logs an exception",
                logs.contains("java.lang.reflect.UndeclaredThrowableException"));
        assertTrue("should have written in logs an exception", logs.contains("BonitaException"));
        assertTrue("should have written in logs an exception", logs.contains("Exception plop"));
    }
}

From source file:com.github.jessemull.microflex.stat.statdouble.GeometricMeanDoubleWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *//*from   w w w .  j a v  a  2s . com*/
@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++) {

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

        array[j] = plate;
    }

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

        PlateDouble plateIndices = RandomUtil.randomPlateDouble(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:com.twitter.heron.common.utils.logging.LoggingHelper.java

/**
 * Init java util logging//w  w  w.j  ava 2  s.  co m
 *
 * @param level the Level of message to log
 * @param isRedirectStdOutErr whether we redirect std out&amp;err
 * @param format the format to log
 */
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
    // Set the java util logging format
    setLoggingFormat(format);

    // Configure the root logger and its handlers so that all the
    // derived loggers will inherit the properties
    Logger rootLogger = Logger.getLogger("");
    for (Handler handler : rootLogger.getHandlers()) {
        handler.setLevel(level);
    }

    rootLogger.setLevel(level);

    if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
        // zookeeper logging scares me. if people want this, we can patch to config-drive this
        Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
    }

    // setting logging for http client to be error level
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "ERROR");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "ERROR");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "ERROR");

    if (isRedirectStdOutErr) {

        // Remove ConsoleHandler if present, to avoid StackOverflowError.
        // ConsoleHandler writes to System.err and since we are redirecting
        // System.err to Logger, it results in an infinite loop.
        for (Handler handler : rootLogger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                rootLogger.removeHandler(handler);
            }
        }

        // now rebind stdout/stderr to logger
        Logger logger;
        LoggingOutputStream los;

        logger = Logger.getLogger("stdout");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
        System.setOut(new PrintStream(los, true));

        logger = Logger.getLogger("stderr");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
        System.setErr(new PrintStream(los, true));
    }
}

From source file:com.github.jessemull.microflex.stat.statinteger.GeometricMeanIntegerWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 */// w w w . j a  v a  2 s. com
@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++) {

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

        array[j] = plate;
    }

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

        PlateInteger plateIndices = RandomUtil.randomPlateInteger(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:dev.agustin.serializer.MainWindow.java

private void setOutputStreamToScreen() {
    PrintStream str = new PrintStream(consoleOutput, true);
    System.setOut(str);
    System.setErr(str);
}

From source file:org.xwiki.test.webstandards.framework.DefaultValidationTest.java

@Override
protected void tearDown() throws Exception {
    // Restore original stdout and stderr streams.
    String output = this.out.toString();
    String errput = this.err.toString();

    System.setOut(this.stdout);
    System.out.print(output);//from  w w w.  j  a va  2  s . c o  m
    System.setErr(this.stderr);
    System.err.print(errput);

    // Detect server-side error/warning messages from the stdout
    assertFalse("Errors found in the stdout output", hasLogErrors(output));
    assertFalse("Warnings found in the stdout output", hasLogWarnings(output));

    // Detect server-side error/warning messages from the stderr
    assertFalse("Errors found in the stderr output", hasLogErrors(errput));
    assertFalse("Warnings found in the stderr output", hasLogWarnings(errput));

    super.tearDown();
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.GeometricMeanBigDecimalTest.java

/**
 * Generates random objects and numbers for testing.
 *///from   w  w w .  j a  va 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++) {

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

        array[j] = plate;
    }

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

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

        arrayIndices[j] = plateIndices;
    }
}

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

/**
 * Generates random objects and numbers for testing.
 *///from   ww w .  j  av  a2  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++) {

        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;
    }
}

From source file:com.complexible.stardog.ext.spring.batch.TestSpringBatch.java

/**
 * We'll add 20 triples of the form:/* www  . j ava 2  s .c  o  m*/
 *   
 *   <urn:test:resource> <urn:test:predicate> "lit{0..20}"
 * 
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
    SnarlTemplate tmp = new SnarlTemplate();
    tmp.setDataSource(dataSource);
    tmp.doWithAdder(new AdderCallback<Boolean>() {
        @Override
        public Boolean add(Adder adder) throws StardogException {
            String uriA = "urn:test:resource";
            String uriB = "urn:test:predicate";

            for (int i = 0; i < 20; i++) {
                adder.statement(new URIImpl(uriA), new URIImpl(uriB), new LiteralImpl("lit" + i));
            }
            return true;
        }
    });

}