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.heliosdecompiler.helios.transformers.disassemblers.BaksmaliDisassembler.java

public boolean disassembleClassNode(ClassNode cn, byte[] b, StringBuilder output) {
    try {//from w  w  w .ja  v a 2s.  co  m
        PrintStream oldErr = System.err;
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        System.setErr(new PrintStream(outputStream));

        DexOptions dexOptions = new DexOptions();
        dexOptions.targetApiLevel = DexFormat.API_NO_EXTENDED_OPCODES;
        OUTPUT_DEX.invoke(new com.android.dx.dex.file.DexFile(dexOptions));
        Main.Arguments args = new Main.Arguments();
        args.parse(new String[] { "--no-strict", "Helios.class" });
        ARGS.invoke(args);

        PROCESS_FILE_BYTES.invoke("Helios.class", System.currentTimeMillis(), b);
        byte[] bytes = (byte[]) WRITE_DEX.invoke();

        OUTPUT_DEX.invoke((Object) null);
        ARGS.invoke((Object) null);

        baksmaliOptions options = new baksmaliOptions();
        options.deodex = true;
        DexFile file = new DexBackedDexFile(Opcodes.forApi(options.apiLevel), bytes);
        Iterator<? extends ClassDef> it = file.getClasses().iterator();

        System.setErr(oldErr);

        if (it.hasNext()) {
            ClassDefinition classDefinition = new ClassDefinition(options, it.next());
            classDefinition.writeTo(new IndentingWriter(new StringBuilderWriter(output)));
            return true;
        } else {
            throw new IllegalStateException("Baksmali failed to read the class file\n"
                    + new String(outputStream.toByteArray(), "UTF-8"));
        }
    } catch (final Throwable e) {
        output.setLength(0);
        output.append(parseException(e));
        return false;
    }
}

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

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

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

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

/**
 * Generates random objects and numbers for testing.
 *//*w w  w  .j a  va2  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.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;
    }
}

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

@Override
protected void setUp() throws Exception {
    super.setUp();

    // TODO Until we find a way to incrementally display the result of tests this stays
    System.out.println(getName());

    // We redirect the stdout and the stderr in order to detect (server-side) error/warning
    // messages like the ones generated by the velocity parser
    this.stdout = System.out;
    this.out = new ByteArrayOutputStream();
    System.setOut(new PrintStream(this.out));
    this.stderr = System.err;
    this.err = new ByteArrayOutputStream();
    System.setErr(new PrintStream(this.err));
}

From source file:org.spoutcraft.launcher.entrypoint.SpoutcraftLauncher.java

protected static Logger setupLogger() {
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(Utils.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();//from  w  w  w.  j a va  2s . c o m
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new TechnicLogFormatter());

    for (Handler h : logger.getHandlers()) {
        logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);

    SpoutcraftLauncher.handler = fileHandler;

    if (params != null && !params.isDebugMode()) {
        logger.setUseParentHandlers(false);

        System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
        System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    }

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);

            if (errorDialog == null) {
                LauncherFrame frame = null;

                try {
                    frame = Launcher.getFrame();
                } catch (Exception ex) {
                    //This can happen if we have a very early crash- before Launcher initializes
                }

                errorDialog = new ErrorDialog(frame, e);
                errorDialog.setVisible(true);
            }
        }
    });

    return logger;
}

From source file:org.apache.hadoop.hive.ql.session.TestClearDanglingScratchDir.java

public void rollbackStdOutErr() {
    System.setOut(origStdoutPs);
    System.setErr(origStderrPs);
}

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

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

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

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

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

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

From source file:org.sonar.scanner.mediumtest.log.LogListenerTest.java

@Before
public void prepare() throws IOException {
    stdOutTarget = new ByteArrayOutputStream();
    stdErrTarget = new ByteArrayOutputStream();
    System.setOut(new PrintStream(stdOutTarget));
    System.setErr(new PrintStream(stdErrTarget));
    // logger from the batch might write to it asynchronously
    logOutput = Collections.synchronizedList(new LinkedList<LogEvent>());
    logOutputStr = new StringBuilder();
    tester.start();/*w w w  . jav  a  2  s.c  om*/

    baseDir = temp.getRoot();

    builder = ImmutableMap.<String, String>builder().put("sonar.task", "scan")
            .put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project")
            .put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT")
            .put("sonar.projectDescription", "Description of Foo Project");
}

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

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