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.axis2.util.PrettyPrinter.java

/**
 * Pretty prints contents of the java source file.
 *
 * @param file//from www.  j  a v  a 2  s .co m
 */
public static void prettify(File file) {
    // If the user has set "axis2.jalopy=false" on the system property,
    // then just return back to caller
    String property = System.getProperty("axis2.jalopy");
    if ((property == null) || !JavaUtils.isTrueExplicitly(property)) {
        return;
    }
    PrintStream backupOutputStream = System.out;
    PrintStream backupErrorStream = System.err;
    System.setOut(new PrintStream(new ByteArrayOutputStream()));
    System.setErr(new PrintStream(new ByteArrayOutputStream()));
    try {
        Class clazzConfigurator = Loader.loadClass("org.apache.log4j.PropertyConfigurator");
        Method configure = clazzConfigurator.getMethod("configure", new Class[] { Properties.class });
        Properties properties = new Properties();
        properties.setProperty("log4j.logger.de.hunsicker.jalopy.io",
                System.getProperty("log4j.logger.de.hunsicker.jalopy.io", "FATAL"));
        configure.invoke(null, new Object[] { properties });

        // Create an instance of the Jalopy bean
        Class clazz = Loader.loadClass("de.hunsicker.jalopy.Jalopy");
        Object prettifier = clazz.newInstance();

        // Set the input file
        Method input = clazz.getMethod("setInput", new Class[] { File.class });
        input.invoke(prettifier, new Object[] { file });

        // Set the output file
        Method output = clazz.getMethod("setOutput", new Class[] { File.class });
        output.invoke(prettifier, new Object[] { file });

        Class clazz2 = Loader.loadClass("de.hunsicker.jalopy.storage.Convention");
        Method instance = clazz2.getMethod("getInstance", new Class[] {});
        Object settings = instance.invoke(null, new Object[] {});

        Class clazz3 = Loader.loadClass("de.hunsicker.jalopy.storage.ConventionKeys");
        Field field = clazz3.getField("COMMENT_FORMAT_MULTI_LINE");
        Object key = field.get(null);
        Method put = clazz2.getMethod("put", new Class[] { key.getClass(), String.class });
        put.invoke(settings, new Object[] { key, "true" });

        // format and overwrite the given input file
        Method format = clazz.getMethod("format", new Class[] {});
        format.invoke(prettifier, new Object[] {});
        log.debug("Pretty printed file : " + file);
    } catch (ClassNotFoundException e) {
        log.debug("Jalopy/Log4j not found - unable to pretty print " + file);
    } catch (Exception e) {
        log.warn("Exception occurred while trying to pretty print file " + file, e);
    } catch (Throwable t) {
        log.debug("Exception occurred while trying to pretty print file " + file, t);
    } finally {
        System.setOut(backupOutputStream);
        System.setErr(backupErrorStream);
    }
}

From source file:alluxio.cli.fs.command.ChownCommandTest.java

@Before
public void setupStreams() {
    System.setOut(new PrintStream(mOutput));
    System.setErr(new PrintStream(mError));
}

From source file:org.aksw.gerbil.web.config.RootConfig.java

protected static void replaceSystemStreams() {
    System.setOut(new PrintStream(new ConsoleLogger(false), true));
    System.setErr(new PrintStream(new ConsoleLogger(true), true));
}

From source file:org.sonatype.flexmojos.test.ProgressListener.java

@Override
public void onStart(ITestContext testContext) {
    super.onStart(testContext);

    out = System.out;//from  ww  w .  j a v a2 s .c  o  m
    err = System.err;
    System.setOut(new PrintStream(new NullOutputStream()));
    System.setErr(new PrintStream(new NullOutputStream()));
}

From source file:alluxio.cli.fs.command.ChownCommandTest.java

@After
public void cleanupStreams() {
    System.setOut(null);
    System.setErr(null);
}

From source file:net.lightbody.bmp.proxy.jetty.log.LogStream.java

/** Log standard error stream.
 * If set to true, output to stderr will be directed to an instance
 * of LogStream and logged.  Beware of log loops from logs that write to stderr.
 *//* w w  w  . j  a v  a  2  s  . c  o  m*/
public static void setLogStdErr(boolean log) {
    if (log) {
        if (!(System.err instanceof LogStream))
            System.setErr(new LogStream.STDERR());
    } else
        System.setErr(STDERR_STREAM);
}

From source file:corina.logging.CorinaLog.java

public static void init() {
    System.setOut(createPrintStream(STDOUT, false));
    System.setErr(createPrintStream(STDERR, true));
}

From source file:javancss.ParseDebugTest.java

@Override
protected Javancss measureTestFile(int testFileId) {
    Logger logger = Logger.getLogger("javancss");
    logger.setLevel(Level.FINEST);

    PrintStream stdout = System.out;
    PrintStream stderr = System.err;

    try {//from   w w w  . ja v a 2 s  . c  o  m
        System.setOut(new PrintStream(new NullOutputStream()));
        System.setErr(new PrintStream(new NullOutputStream()));

        return super.measureTestFile(testFileId);
    } finally {
        logger.setLevel(Level.OFF);
        System.setOut(stdout);
        System.setErr(stderr);
    }
}

From source file:net.jperf.LoggingStopWatchTest.java

protected void setUp() throws Exception {
    realErr = System.err;//from w  w  w .  java  2s.c  o m
    fakeErr = new ByteArrayOutputStream();
    System.setErr(new PrintStream(fakeErr, true /*autoflush*/));
}

From source file:org.sonatype.flexmojos.test.ProgressListener.java

@Override
public void onFinish(ITestContext testContext) {
    super.onFinish(testContext);

    System.setOut(out);
    System.setErr(err);
}