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:nl.xs4all.home.freekdb.b52reader.general.Utilities.java

/**
 * Ignore characters written to the standard error stream. This is used because the dj-nativeswing library sometimes
 * has difficulties with the contents of the clipboard, resulting in <code>ClassNotFoundException</code>s.
 */// ww  w  .  ja  va2s . c om
public static void ignoreStandardErrorStream() {
    // Ignore characters written to the standard error stream, since the dj-nativeswing library sometimes has
    // difficulties with the contents of the clipboard, resulting in ClassNotFoundException-s.
    try (OutputStream outputStream = getIgnorantStream()) {
        System.setErr(new PrintStream(outputStream, false, "UTF-8"));
    } catch (final IOException e) {
        logger.error("Exception while redirecting the standard error stream.", e);
    }
}

From source file:org.apache.tools.ant.listener.CommonsLoggingListener.java

private Log getLog(String cat, String suffix) {
    if (suffix != null) {
        suffix = suffix.replace('.', '-');
        suffix = suffix.replace(' ', '-');
        cat = cat + "." + suffix;
    }//from   w  w w .j av  a2 s .c o m
    final PrintStream tmpOut = System.out;
    final PrintStream tmpErr = System.err;
    System.setOut(out);
    System.setErr(err);

    if (!initialized) {
        try {
            logFactory = LogFactory.getFactory();
        } catch (final LogConfigurationException e) {
            e.printStackTrace(System.err);
            return null;
        }
    }

    initialized = true;
    final Log log = logFactory.getInstance(cat);
    System.setOut(tmpOut);
    System.setErr(tmpErr);
    return log;
}

From source file:TestOpenMailRelay.java

/** Try the given mail server, writing output to the given PrintStream */
public static void process(String suspect_relay, PrintStream pw) {
    pw.println("processs: trying: " + suspect_relay);
    try {//from   w ww . j  a  v  a 2 s .  c o m
        // Redirect all output from mail API to the given stream.
        System.setOut(pw);
        System.setErr(pw);
        Sender2 sm = new Sender2(suspect_relay);
        sm.addRecipient("nobody@erewhon.moc");
        sm.setFrom(MY_TARGET);
        sm.setSubject("Testing for open mail relay, see " + RSS_SITE);
        sm.setBody("This mail is an attempt to confirm that site " + suspect_relay + "\n"
                + "is in fact an open mail relay site.\n"
                + "For more information on the problem of open mail relays,\n" + "please visit site " + RSS_SITE
                + "\n" + "Please join the fight against spam by closing all open mail relays!\n"
                + "If this open relay has been closed, please accept our thanks.\n");
        sm.sendFile("");
    } catch (MessagingException e) {
        pw.println(e);
    } catch (Exception e) {
        pw.println(e);
    }
}

From source file:com.bc.fiduceo.matchup.MatchupToolIntegrationTest.java

private String callMatchupToolMain_wrappedWithSystemErrSpy(String[] args)
        throws ParseException, IOException, SQLException, InvalidRangeException {
    final PrintStream err = System.err;
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(out);

    try {//from   w  ww .j  av a  2s.  c o  m
        System.setErr(printStream);

        MatchupToolMain.main(args);
    } finally {
        System.setErr(err);
    }
    printStream.close();
    return out.toString();
}

From source file:net.sf.mpaxs.spi.computeHost.Host.java

@Override
public void configure(Configuration cfg) {
    settings = new Settings(cfg);
    Logger.getLogger(Host.class.getName()).log(Level.INFO, "Running ComputeHost at IP {0}",
            settings.getLocalIp());/*  ww w  .  j a  va 2 s. com*/
    File baseDir = new File(settings.getOption(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR));
    try {
        //remove leftovers from previous run
        FileUtils.deleteDirectory(baseDir);
    } catch (IOException ex) {
        Logger.getLogger(Host.class.getName()).log(Level.SEVERE, null, ex);
    }
    baseDir.mkdirs();
    settings.setOption(ConfigurationKeys.KEY_COMPUTE_HOST_ERROR_FILE,
            new File(baseDir, "error.txt").getAbsolutePath());
    settings.setOption(ConfigurationKeys.KEY_COMPUTE_HOST_OUTPUT_FILE,
            new File(baseDir, "output.txt").getAbsolutePath());
    try {
        System.setErr(new PrintStream(
                new FileOutputStream(settings.getOption(ConfigurationKeys.KEY_COMPUTE_HOST_ERROR_FILE))));
        System.setOut(new PrintStream(
                new FileOutputStream(settings.getOption(ConfigurationKeys.KEY_COMPUTE_HOST_OUTPUT_FILE))));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Host.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ee.ioc.cs.vsle.util.Console.java

private Console() {
    // create all components and add them
    frame = new JFrame("Java Console");
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = new Dimension((screenSize.width / 2), (screenSize.height / 2));
    int x = (frameSize.width / 2);
    int y = (frameSize.height / 2);
    frame.setBounds(x, y, frameSize.width, frameSize.height);

    textArea = new JTextArea();
    textArea.setEditable(false);/*www .ja v  a2 s.  c  o  m*/
    JButton button = new JButton("clear");

    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER);
    frame.getContentPane().add(button, BorderLayout.SOUTH);
    frame.setVisible(true);

    frame.addWindowListener(this);
    button.addActionListener(this);

    final PipedInputStream pin = new PipedInputStream();
    try {
        PipedOutputStream pout = new PipedOutputStream(pin);
        System.setOut(new PrintStream(new TeeOutputStream(systemOut, pout), true));
    } catch (java.io.IOException io) {
        textArea.append("Couldn't redirect STDOUT to this console\n" + io.getMessage());
    } catch (SecurityException se) {
        textArea.append("Couldn't redirect STDOUT to this console\n" + se.getMessage());
    }

    final PipedInputStream pin2 = new PipedInputStream();
    try {
        PipedOutputStream pout2 = new PipedOutputStream(pin2);
        System.setErr(new PrintStream(new TeeOutputStream(systemErr, pout2), true));
    } catch (java.io.IOException io) {
        textArea.append("Couldn't redirect STDERR to this console\n" + io.getMessage());
    } catch (SecurityException se) {
        textArea.append("Couldn't redirect STDERR to this console\n" + se.getMessage());
    }

    quit = false; // signals the Threads that they should exit

    sysOutFollower = new StreamFollower(pin, StreamRestorer.SYS_OUT, "Console_out");
    sysOutFollower.start();
    //
    sysErrFollower = new StreamFollower(pin2, StreamRestorer.SYS_ERR, "Console_err");
    sysErrFollower.start();
}

From source file:com.github.jessemull.microflexinteger.stat.GeometricMeanWeightsTest.java

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

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

        array[j] = plate;
    }

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

        Plate 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:com.github.jessemull.microflexdouble.stat.GeometricMeanWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *//*from   w ww  .  j a  va  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.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate1-" + j);

        array[j] = plate;
    }

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

        Plate 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.github.jessemull.microflexbigdecimal.stat.GeometricMeanTest.java

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

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

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

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

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