List of usage examples for java.lang System setErr
public static void setErr(PrintStream err)
From source file:flow.visibility.pcap.FlowProcess.java
/** function to create internal frame contain flow details */ public static JInternalFrame FlowInspection() { final StringBuilder errbuf = new StringBuilder(); // For any error msgs final String file = "tmp-capture-file.pcap"; //System.out.printf("Opening file for reading: %s%n", file); /*************************************************************************** * Second we open up the selected file using openOffline call **************************************************************************/ Pcap pcap = Pcap.openOffline(file, errbuf); if (pcap == null) { System.err.printf("Error while opening device for capture: " + errbuf.toString()); }//from w w w .j a va2 s .c om /** create blank internal frame */ JInternalFrame FlowInspection = new JInternalFrame("Flow Inspection", true, true, true, true); FlowInspection.setBounds(601, 0, 600, 660); JTextArea textArea2 = new JTextArea(50, 10); PrintStream printStream2 = new PrintStream(new CustomOutputStream(textArea2)); System.setOut(printStream2); System.setErr(printStream2); JScrollPane scrollPane2 = new JScrollPane(textArea2); FlowInspection.add(scrollPane2); JPacketHandler<String> jpacketHandler = new JPacketHandler<String>() { public void nextPacket(JPacket packet, String user) { final JCaptureHeader header = packet.getCaptureHeader(); System.out.printf("========================= Next Packet ===============================\n"); System.out.printf("Packet caplen=%d wirelen=%d\n", header.caplen(), header.wirelen()); System.out.println(packet.toString()); } }; Pcap pcap3 = Pcap.openOffline(file, errbuf); /** Redirect Output into the Frame Text Area */ FlowInspection.setVisible(true); pcap3.loop(Pcap.LOOP_INFINITE, jpacketHandler, null); FlowInspection.revalidate(); pcap3.close(); return FlowInspection; }
From source file:com.github.jessemull.microflexdouble.math.AdditionTest.java
/** * Generates random objects and numbers for testing. *//*from www . java 2 s .co m*/ @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1); columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1); length = rows * columns / 5; for (int i = 0; i < stackNumber; i++) { plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); Stack stack1 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length, "Plate1-" + i, plateNumber); Stack stack2 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length, "Plate2-" + i, plateNumber); Stack stackUneven = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + i, plateNumber); stacks1.add(stack1); stacks2.add(stack2); stacksUneven.add(stackUneven); } for (int i = 0; i < arrayNumber; i++) { Plate[] array1 = new Plate[plateNumber]; Plate[] array2 = new Plate[plateNumber]; Plate[] unevenArray = new Plate[plateNumber]; for (int j = 0; j < array1.length; j++) { rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1); columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1); plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); length = rows * columns / 5; Plate plate1 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate1-" + j); Plate plate2 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate2-" + j); Plate unevenPlate = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + j); array1[j] = plate1; array2[j] = plate2; unevenArray[j] = unevenPlate; } arrays1.add(array1); arrays2.add(array2); uneven.add(unevenArray); } }
From source file:com.github.jessemull.microflexinteger.math.AdditionTest.java
/** * Generates random objects and numbers for testing. *///from w w w .j a va 2 s .c om @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1); columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1); length = rows * columns / 5; for (int i = 0; i < stackNumber; i++) { plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); Stack stack1 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length, "Plate1-" + i, plateNumber); Stack stack2 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length, "Plate2-" + i, plateNumber); Stack stackUneven = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + i, plateNumber); stacks1.add(stack1); stacks2.add(stack2); stacksUneven.add(stackUneven); } for (int i = 0; i < arrayNumber; i++) { Plate[] array1 = new Plate[plateNumber]; Plate[] array2 = new Plate[plateNumber]; Plate[] unevenArray = new Plate[plateNumber]; for (int j = 0; j < array1.length; j++) { rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1); columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1); plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); length = rows * columns / 5; Plate plate1 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length, "Plate1-" + j); Plate plate2 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length, "Plate2-" + j); Plate unevenPlate = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + j); array1[j] = plate1; array2[j] = plate2; unevenArray[j] = unevenPlate; } arrays1.add(array1); arrays2.add(array2); uneven.add(unevenArray); } }
From source file:com.github.jessemull.microflex.math.mathdouble.AdditionDoubleTest.java
/** * Generates random objects and numbers for testing. *//*from www. ja va 2 s .co m*/ @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } rows = PlateDouble.ROWS_48WELL + random.nextInt(PlateDouble.ROWS_1536WELL - PlateDouble.ROWS_48WELL + 1); columns = PlateDouble.COLUMNS_48WELL + random.nextInt(PlateDouble.COLUMNS_1536WELL - PlateDouble.COLUMNS_48WELL + 1); length = rows * columns / 5; for (int i = 0; i < stackNumber; i++) { plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); StackDouble stack1 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length, "Plate1-" + i, plateNumber); StackDouble stack2 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length, "Plate2-" + i, plateNumber); StackDouble stackUneven = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + i, plateNumber); stacks1.add(stack1); stacks2.add(stack2); stacksUneven.add(stackUneven); } for (int i = 0; i < arrayNumber; i++) { PlateDouble[] array1 = new PlateDouble[plateNumber]; PlateDouble[] array2 = new PlateDouble[plateNumber]; PlateDouble[] unevenArray = new PlateDouble[plateNumber]; for (int j = 0; j < array1.length; j++) { rows = PlateDouble.ROWS_48WELL + random.nextInt(PlateDouble.ROWS_1536WELL - PlateDouble.ROWS_48WELL + 1); columns = PlateDouble.COLUMNS_48WELL + random.nextInt(PlateDouble.COLUMNS_1536WELL - PlateDouble.COLUMNS_48WELL + 1); plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); length = rows * columns / 5; PlateDouble plate1 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate1-" + j); PlateDouble plate2 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate2-" + j); PlateDouble unevenPlate = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + j); array1[j] = plate1; array2[j] = plate2; unevenArray[j] = unevenPlate; } arrays1.add(array1); arrays2.add(array2); uneven.add(unevenArray); } }
From source file:com.github.jessemull.microflex.math.mathinteger.AdditionIntegerTest.java
/** * Generates random objects and numbers for testing. */// w ww .ja v a2 s .co m @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } rows = PlateInteger.ROWS_48WELL + random.nextInt(PlateInteger.ROWS_1536WELL - PlateInteger.ROWS_48WELL + 1); columns = PlateInteger.COLUMNS_48WELL + random.nextInt(PlateInteger.COLUMNS_1536WELL - PlateInteger.COLUMNS_48WELL + 1); length = rows * columns / 5; for (int i = 0; i < stackNumber; i++) { plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); StackInteger stack1 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length, "Plate1-" + i, plateNumber); StackInteger stack2 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length, "Plate2-" + i, plateNumber); StackInteger stackUneven = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + i, plateNumber); stacks1.add(stack1); stacks2.add(stack2); stacksUneven.add(stackUneven); } for (int i = 0; i < arrayNumber; i++) { PlateInteger[] array1 = new PlateInteger[plateNumber]; PlateInteger[] array2 = new PlateInteger[plateNumber]; PlateInteger[] unevenArray = new PlateInteger[plateNumber]; for (int j = 0; j < array1.length; j++) { rows = PlateInteger.ROWS_48WELL + random.nextInt(PlateInteger.ROWS_1536WELL - PlateInteger.ROWS_48WELL + 1); columns = PlateInteger.COLUMNS_48WELL + random.nextInt(PlateInteger.COLUMNS_1536WELL - PlateInteger.COLUMNS_48WELL + 1); plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1); length = rows * columns / 5; PlateInteger plate1 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length, "Plate1-" + j); PlateInteger plate2 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length, "Plate2-" + j); PlateInteger unevenPlate = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length + length / 2, "Plate2-" + j); array1[j] = plate1; array2[j] = plate2; unevenArray[j] = unevenPlate; } arrays1.add(array1); arrays2.add(array2); uneven.add(unevenArray); } }
From source file:org.apache.jackrabbit.oak.run.DataStoreCheckTest.java
public static void testIncorrectParams(List<String> argList, String assertMsg) throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); System.setErr(new PrintStream(buffer, true, UTF_8.toString())); DataStoreCheckCommand checkCommand = new DataStoreCheckCommand(); checkCommand.execute(argList.toArray(new String[0])); String message = buffer.toString(UTF_8.toString()); log.info("Assert message: {}", assertMsg); log.info("Message logged in System.err: {}", message); Assert.assertTrue(message.contains(assertMsg)); System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err))); }
From source file:mil.dod.th.ose.junit4xmltestrunner.ant.XMLJUnitResultFormatter.java
/** * The whole test suite started.//from w w w .j av a 2s .c om */ public void startTestSuite(final String name) // NOCHECKSTYLE: no documentation, file modified from 3rd party { m_Doc = getDocumentBuilder().newDocument(); m_RootElement = m_Doc.createElement(TESTSUITE); m_RootElement.setAttribute(ATTR_NAME, name); //add the timestamp final String timestamp = DateUtils.format(new Date(), DateUtils.ISO8601_DATETIME_PATTERN); m_RootElement.setAttribute(TIMESTAMP, timestamp); //and the hostname. m_RootElement.setAttribute(HOSTNAME, getHostname()); // Output properties final Element propsElement = m_Doc.createElement(PROPERTIES); m_RootElement.appendChild(propsElement); final Properties props = System.getProperties(); if (props != null) { final Enumeration<?> e = props.propertyNames(); while (e.hasMoreElements()) { final String propName = (String) e.nextElement(); final Element propElement = m_Doc.createElement(PROPERTY); propElement.setAttribute(ATTR_NAME, propName); propElement.setAttribute(ATTR_VALUE, props.getProperty(propName)); propsElement.appendChild(propElement); } } m_OldStdOut = System.out; System.setOut(new PrintStream(m_TeeOutStream)); m_OldStdErr = System.err; System.setErr(new PrintStream(m_TeeErrStream)); }
From source file:Alias2.java
public void dispose() { System.setOut(console); System.setErr(err); System.setIn(stdin); }
From source file:com.enioka.jqm.tools.JqmEngine.java
/** * Starts the engine// w w w .j a va 2 s . c om * * @param nodeName * the name of the node to start, as in the NODE table of the database. * @throws JqmInitError */ void start(String nodeName) { if (nodeName == null || nodeName.isEmpty()) { throw new IllegalArgumentException("nodeName cannot be null or empty"); } // Set thread name - used in audits Thread.currentThread().setName("JQM engine;;" + nodeName); Helpers.setLogFileName(nodeName); // Log: we are starting... jqmlogger.info("JQM engine version " + this.getVersion() + " for node " + nodeName + " is starting"); jqmlogger.info("Java version is " + System.getProperty("java.version") + ". JVM was made by " + System.getProperty("java.vendor") + " as " + System.getProperty("java.vm.name") + " version " + System.getProperty("java.vm.version")); // JNDI first - the engine itself uses JNDI to fetch its connections! Helpers.registerJndiIfNeeded(); // Database connection EntityManager em = Helpers.getNewEm(); // Node configuration is in the database node = em.createQuery("SELECT n FROM Node n WHERE n.name = :l", Node.class).setParameter("l", nodeName) .getSingleResult(); // Check if double-start long toWait = (long) (1.1 * Long.parseLong(Helpers.getParameter("internalPollingPeriodMs", "60000", em))); if (node.getLastSeenAlive() != null && Calendar.getInstance().getTimeInMillis() - node.getLastSeenAlive().getTimeInMillis() <= toWait) { long r = Calendar.getInstance().getTimeInMillis() - node.getLastSeenAlive().getTimeInMillis(); throw new JqmInitErrorTooSoon("Another engine named " + nodeName + " was running less than " + r / 1000 + " seconds ago. Either stop the other node, or if it already stopped, please wait " + (toWait - r) / 1000 + " seconds"); } // Prevent very quick multiple starts by immediately setting the keep-alive em.getTransaction().begin(); node.setLastSeenAlive(Calendar.getInstance()); em.getTransaction().commit(); // Only start if the node configuration seems OK Helpers.checkConfiguration(nodeName, em); // Log parameters Helpers.dumpParameters(em, node); // Log level Helpers.setLogLevel(node.getRootLogLevel()); // Log multicasting (& log4j stdout redirect) GlobalParameter gp1 = em .createQuery("SELECT g FROM GlobalParameter g WHERE g.key = :k", GlobalParameter.class) .setParameter("k", "logFilePerLaunch").getSingleResult(); if ("true".equals(gp1.getValue()) || "both".equals(gp1.getValue())) { RollingFileAppender a = (RollingFileAppender) Logger.getRootLogger().getAppender("rollingfile"); MultiplexPrintStream s = new MultiplexPrintStream(System.out, FilenameUtils.getFullPath(a.getFile()), "both".equals(gp1.getValue())); System.setOut(s); ((ConsoleAppender) Logger.getRootLogger().getAppender("consoleAppender")) .setWriter(new OutputStreamWriter(s)); s = new MultiplexPrintStream(System.err, FilenameUtils.getFullPath(a.getFile()), "both".equals(gp1.getValue())); System.setErr(s); } // Remote JMX server if (node.getJmxRegistryPort() != null && node.getJmxServerPort() != null && node.getJmxRegistryPort() > 0 && node.getJmxServerPort() > 0) { JmxAgent.registerAgent(node.getJmxRegistryPort(), node.getJmxServerPort(), node.getDns()); } else { jqmlogger.info( "JMX remote listener will not be started as JMX registry port and JMX server port parameters are not both defined"); } // Jetty this.server = new JettyServer(); this.server.start(node, em); // JMX if (node.getJmxServerPort() != null && node.getJmxServerPort() > 0) { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); name = new ObjectName("com.enioka.jqm:type=Node,name=" + this.node.getName()); mbs.registerMBean(this, name); } catch (Exception e) { throw new JqmInitError("Could not create JMX beans", e); } jqmlogger.info("JMX management bean for the engine was registered"); } else { loadJmxBeans = false; jqmlogger.info("JMX management beans will not be loaded as JMX server port is null or zero"); } // Security if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManagerPayload()); } jqmlogger.info("Security manager was registered"); // Cleanup purgeDeadJobInstances(em, this.node); // Force Message EMF load em.createQuery("SELECT m FROM Message m WHERE 1=0", Message.class).getResultList(); // Pollers syncPollers(em, this.node); jqmlogger.info("All required queues are now polled"); // Internal poller (stop notifications, keepalive) intPoller = new InternalPoller(this); Thread t = new Thread(intPoller); t.start(); // Kill notifications killHook = new SignalHandler(this); Runtime.getRuntime().addShutdownHook(killHook); // Done em.close(); em = null; latestNodeStartedName = node.getName(); jqmlogger.info("End of JQM engine initialization"); }
From source file:org.spoutcraft.launcher.Main.java
private static void setupLogger() { Logger logger = Logger.getLogger("launcher"); File logDirectory = new File(Utils.getWorkingDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir();/*from ww w . j a va2 s .com*/ } File logs = new File(logDirectory, "spoutcraft_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new DateOutputFormatter(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"))); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); Main.handler = fileHandler; logger.setUseParentHandlers(false); System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(Level.SEVERE, logger), true)); Main.logger = logger; }