List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file) throws FileNotFoundException
From source file:Main.java
/** * Converts an exception to a string.//from www . j a v a 2s.c om * @param exception * @return */ public static String getExceptionStackTraceAsString(Exception exception) { StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); return sw.toString(); }
From source file:Main.java
/** * Print xml to System.out./* w w w .jav a 2 s .com*/ * * @param xml XML */ public static void println(byte[] xml) throws Exception { FileCopyUtils.copy(new InputStreamReader(new ByteArrayInputStream(xml), "utf8"), new PrintWriter(System.out)); System.out.println(); System.out.flush(); }
From source file:Main.java
/** * Print all running threads/* w w w. j a v a 2 s .c o m*/ */ public static void printRunningThreads() { // Get the thread listing as a string using a StringWriter stream StringWriter stringWriter = new StringWriter(); PrintWriter out = new PrintWriter(stringWriter); listAllThreads(out); out.close(); String threadListing = stringWriter.toString(); System.out.println(threadListing); }
From source file:Main.java
/** * This return exception as string./*from www .jav a 2 s . c o m*/ * * @param throwable Throwable * @return exception string */ public static String exceptionToString(Throwable throwable) { StringWriter errors = new StringWriter(); throwable.printStackTrace(new PrintWriter(errors)); return errors.toString(); }
From source file:Main.java
/** * Get the Stack trace from throwable instance. * * @param t Exception to be print.//from w w w.j a v a 2 s .c o m * @return String formed stack Trace. */ public static String getStack(Throwable t) { if (t == null) return null; StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); return sw.toString(); }
From source file:Main.java
/** * get stack trace as string/* w ww . j a v a 2 s .c o m*/ * * @param traceElements * - stack trace elements * @return built string */ public static String getStackTrace(Throwable throwable) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); String string = sw.toString(); return string; }
From source file:Main.java
/** * Run a command with the given data as input. *///from ww w .j a v a 2 s . c o m public static void systemIn(String command, String data) throws Exception { String cmd[] = new String[3]; cmd[0] = System.getProperty("SHELL", "/bin/sh"); cmd[1] = "-c"; cmd[2] = command; Process p = Runtime.getRuntime().exec(cmd); PrintWriter w = new PrintWriter(p.getOutputStream()); w.print(data); w.flush(); w.close(); p.waitFor(); }
From source file:Main.java
/** * Run a command with the given data as input. *//*from w w w . j a va 2 s .com*/ public static void systemIn(String command, String data) throws Exception { String[] cmd = new String[3]; cmd[0] = System.getProperty("SHELL", "/bin/sh"); cmd[1] = "-c"; cmd[2] = command; Process p = Runtime.getRuntime().exec(cmd); PrintWriter w = new PrintWriter(p.getOutputStream()); w.print(data); w.flush(); w.close(); p.waitFor(); }
From source file:Main.java
/** * dump the exception to string// w w w . j ava 2 s . c o m */ public static String dumpException(Throwable throwable) { StringWriter stringWriter = new StringWriter(160); stringWriter.write(throwable.getClass().getName()); stringWriter.write(":\n"); throwable.printStackTrace(new PrintWriter(stringWriter)); return stringWriter.toString(); }
From source file:com.archivas.clienttools.arcmover.cli.ArcProfileMgr.java
@SuppressWarnings({ "UseOfSystemOutOrSystemErr" }) public static void main(String args[]) { ArcProfileMgr arcProfileMgr = null;//from w w w. ja v a2s . c o m ConfigurationHelper.validateLaunchOK(); try { arcProfileMgr = new ArcProfileMgr(args); arcProfileMgr.parseArgs(); if (arcProfileMgr.printHelp) { System.out.println(arcProfileMgr.helpScreen()); } else { arcProfileMgr.execute(new PrintWriter(System.out), new PrintWriter(System.err)); } } catch (ParseException e) { System.out.println("Error: " + e.getMessage()); System.out.println(); System.out.println(arcProfileMgr.helpScreen()); arcProfileMgr.setExitCode(EXIT_CODE_OPTION_PARSE_ERROR); } catch (Exception e) { LOG.log(Level.SEVERE, "Unexpected Exception.", e); System.out.println(); System.out.println("Failed to create a new profile " + e.getMessage()); arcProfileMgr.setExitCode(EXIT_CODE_DM_ERROR); } finally { if (arcProfileMgr != null) { arcProfileMgr.exit(); } } }