Example usage for java.io PrintStream PrintStream

List of usage examples for java.io PrintStream PrintStream

Introduction

In this page you can find the example usage for java.io PrintStream PrintStream.

Prototype

public PrintStream(File file) throws FileNotFoundException 

Source Link

Document

Creates a new print stream, without automatic line flushing, with the specified file.

Usage

From source file:com.polyvi.xface.exceptionReporter.XCrashInfo.java

/**
 * ?//  w w  w  .ja  v  a2  s  .  co m
 * @param ex
 * @return ?
 */
private JSONObject getExceptionInfo(Throwable ex) {
    JSONObject exceptionInfo = new JSONObject();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(baos);
    ex.printStackTrace(printStream);
    byte[] data = baos.toByteArray();
    String info = new String(data);
    Throwable cause = ex.getCause();
    try {
        exceptionInfo.put(TAG_EXCEPTION_NAME, ex.getClass().getSimpleName());
        exceptionInfo.put(TAG_EXCEPTION_REASON, null == cause ? "unknown cause" : cause.toString());
        exceptionInfo.put(TAG_STACK_TRACE, info);
    } catch (JSONException e) {
        XLog.e(CLASS_NAME, "JSONException:", e.getMessage());
        return null;
    }
    return exceptionInfo;
}

From source file:com.openkm.servlet.admin.UnitTestingServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("doGet({}, {})", request, response);
    String test = WebUtils.getString(request, "test");
    response.setContentType("text/html; charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    OutputStream os = response.getOutputStream();
    PrintStream ps = new PrintStream(os);

    header(ps, "Unit testing", breadcrumb);
    ps.flush();//from ww w.jav a2 s  . c om

    RunListener listener = new CustomListener(ps);
    JUnitCore junit = new JUnitCore();
    junit.addListener(listener);

    if (test != null && !test.isEmpty()) {
        try {
            Class<?> clazz = Class.forName(test);
            ps.println("<b>" + clazz.getCanonicalName() + "</b><br/>");
            ps.flush();
            ps.println("<pre>");
            ps.flush();
            junit.run(clazz);
            ps.println("</pre>");
            ps.flush();
        } catch (ClassNotFoundException e) {
            warn(ps, e.getMessage());
        }
    } else {
        for (Class<?> clazz : new Reflections("com.openkm.test.api").getSubTypesOf(TestCase.class)) {
            ps.println("<a style=\"color: black; font-weight:bold;\" href=\"UnitTesting?test="
                    + clazz.getCanonicalName() + "\">" + clazz.getCanonicalName() + "</a><br/>");
            ps.flush();
            ps.println("<pre>");
            ps.flush();
            junit.run(clazz);
            ps.println("</pre>");
            ps.flush();
        }
    }

    ps.println(
            "<span style=\"color: blue; font-weight:bold;\">&gt;&gt;&gt; End Of Unit Testing &lt;&lt;&lt;</span>");
    footer(ps);
    ps.flush();
    IOUtils.closeQuietly(ps);
    IOUtils.closeQuietly(os);
}

From source file:jetbrains.exodus.sshd.RhinoCommand.java

@Override
public void setOutputStream(OutputStream out) {
    this.out = new PrintStream(out);
}

From source file:com.sangupta.clitools.file.HexDump.java

private void execute() {
    File file = new File(this.filePath);

    InputStream is = null;//from  w  ww  .j ava2s  . co m
    BufferedInputStream bis = null;

    PrintStream outStream = null;
    try {
        is = new FileInputStream(file);
        bis = new BufferedInputStream(is);

        if (this.outputAsFile) {
            outStream = new PrintStream(
                    new BufferedOutputStream(new FileOutputStream(new File(file.getAbsolutePath() + ".hex"))));
        } else {
            outStream = System.out;
        }

        int currentRow = 0;
        do {
            hexDump(outStream, bis, currentRow, 16);
            currentRow += 16;

            if (bis.available() <= 0) {
                break;
            }

            if (!this.outputAsFile) {
                // ask user to continue or exit
                String input = ConsoleUtils.readLine(":", true);
                if ("q".equalsIgnoreCase(input)) {
                    break;
                }
            }
        } while (true);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(bis);
        if (this.outputAsFile) {
            IOUtils.closeQuietly(outStream);
        }
    }
}

From source file:fi.jumi.core.suite.InternalErrorReportingExecutorTest.java

@Test
public void the_toString_of_the_original_commands_should_not_be_hidden() {
    SpyExecutor backingExecutor = new SpyExecutor();
    InternalErrorReportingExecutor executor = new InternalErrorReportingExecutor(backingExecutor, suiteListener,
            new PrintStream(new NullOutputStream()));
    Runnable originalCommand = () -> {
    };//from   w  ww  .j a  v  a  2  s. c o m

    executor.execute(originalCommand);

    assertThat(backingExecutor.lastCommand.toString(), containsString(originalCommand.toString()));
}

From source file:graphgen.GraphGen.java

private static void saveGraph(String graph, String fileName) throws FileNotFoundException {
    PrintStream out = new PrintStream(new FileOutputStream(fileName));
    out.print(graph);/*from  w  ww. j  av a 2s  .  c  om*/
    System.out.println("Created Graph");
}

From source file:fi.jumi.test.JumiBootstrapTest.java

@Test
public void will_not_close_stderr_when_debug_output_is_enabled() throws Exception {
    PrintStream originalErr = System.err;
    try {/*from   w  w w .  j a v  a  2s. co m*/
        ByteArrayOutputStream printed = new ByteArrayOutputStream();
        PrintStream spiedErr = spy(new PrintStream(printed));
        System.setErr(spiedErr);

        JumiBootstrap bootstrap = new JumiBootstrap();
        bootstrap.suite.setTestClasses(OnePassingTest.class);
        bootstrap.daemon.setIdleTimeout(0); // we want the daemon process to exit quickly
        bootstrap.setTextUiOutput(new NullWriter());
        bootstrap.enableDebugMode(); // <-- the thing we are testing
        bootstrap.runSuite();

        Thread.sleep(50); // wait for the daemon process to exit, and our printer thread to notice it
        assertThat("this test has a problem; daemon printed nothing", printed.size(), is(not(0)));
        verify(spiedErr, never()).close(); // <-- the thing we are testing

    } finally {
        System.setErr(originalErr);
    }
}

From source file:com.mockey.ui.StickyCookieSessionAjaxServlet.java

/**
 * /*from ww  w  . jav  a  2s  .  c om*/
 */
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    JSONObject jsonObject = new JSONObject();
    try {
        ClientExecuteProxy.resetStickySession();

        jsonObject.put("reset", true);

    } catch (Exception e) {
        try {
            jsonObject.put("error", "Unable to reset sticky session");
        } catch (JSONException e1) {
            logger.error("Unable to create JSON", e1);
        }
    }

    resp.setContentType("application/json");

    PrintStream out = new PrintStream(resp.getOutputStream());

    out.println(jsonObject.toString());
}

From source file:com.artnaseef.jmeter.report.HitsPerSecondReport.java

@Override
public void onFeedStart(String uri, Properties reportProperties) throws Exception {
    this.feedUri = uri;

    this.extractReportProperties(reportProperties);

    this.chartSeries = new XYSeries("Hits");
    this.dataset = new XYSeriesCollection();
    this.hitsPerSecond = new TreeMap<Long, Long>();

    if (this.detailOutputFile != null) {
        this.detailFileWriter = new PrintStream(this.detailOutputFile);
    }/*www  .  java  2 s. c om*/
}

From source file:com.karpenstein.signalmon.NetConnHandler.java

@Override
public void run() {

    server.addListener(this);

    String line;//  w w w . java 2  s  .  c  o m
    try {
        Log.d("NetConnHandler", "about to create input and output streams");
        // Get input from the client
        DataInputStream in = new DataInputStream(sock.getInputStream());
        PrintStream out = new PrintStream(sock.getOutputStream());

        Log.d("NetConnHandler", "about to start looping");
        while ((line = in.readLine()) != null && line.equals("G")) {
            if (stateChanged) {
                stateChanged = false;
                out.println(state.toString());
            } else
                out.println(nullObj);
        }

        sock.close();
    } catch (IOException ioe) {
        Log.e("SignalMonitor.NetConnHandler", "IOException on socket r/w: " + ioe, ioe);
    }

}