List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file) throws FileNotFoundException
From source file:mx.unam.ecologia.gye.coalescence.app.CreateMicsatInput.java
protected static final void writeMicsat(List leaves, String fname) { try {//w ww . ja va 2 s . co m FileOutputStream fout = new FileOutputStream(fname); PrintWriter pw = new PrintWriter(fout); for (int i = 0; i < leaves.size(); i++) { UniParentalGene upgene = (UniParentalGene) leaves.get(i); CompoundSequence h = upgene.getCompoundSequence(); int numloc = h.getSequenceCount(); for (int n = 0; n < numloc; n++) { Sequence s = h.get(n); pw.print(s.getSize()); pw.print(" "); } pw.println(); } pw.flush(); pw.close(); fout.close(); } catch (IOException ex) { log.error("writeMicsat()", ex); } }
From source file:Main.java
/** * Print warnings on a Connection to STDERR. * * @param conn Connection to print warnings from */// ww w. ja v a 2 s . com public static void printWarnings(Connection conn) { printWarnings(conn, new PrintWriter(System.err)); }
From source file:com.doubotis.restwrapper.data.JObjectResponse.java
public static JObjectResponse fromException(Exception exception, boolean showStackTrace) { JObjectResponse r = new JObjectResponse(false); StringWriter sw = null;/*from w w w . j av a2 s. co m*/ if (exception instanceof HTTPException && exception.getCause() != null) { sw = new StringWriter(); exception.getCause().printStackTrace(new PrintWriter(sw)); } else { sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); } if (showStackTrace) r.put("stacktrace", sw.toString()); r.put("message", exception.getMessage()); r.put("status", "ko"); return r; }
From source file:Main.java
/** * make throwable to string.//w w w . j a va 2 s. com */ public static String toString(Throwable throwable) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printWriter.print(throwable.getClass().getName() + ": "); if (throwable.getMessage() != null) { printWriter.print(throwable.getMessage() + "\n"); } printWriter.println(); try { throwable.printStackTrace(printWriter); return stringWriter.toString(); } finally { printWriter.close(); } }
From source file:cc.sion.core.utils.Exceptions.java
/** * ErrorStackString.//from w w w . j av a2 s. c o m */ public static String getStackTraceAsString(Throwable ex) { StringWriter stringWriter = new StringWriter(); ex.printStackTrace(new PrintWriter(stringWriter)); return stringWriter.toString(); }
From source file:Main.java
/** * Writes a DOM node (and all its ancestors) to the given output stream * //from w w w. j a v a2s.co m * @param n * the node to write * @param o * the output stream to write the node to */ public static void writeNode(Node n, FileOutputStream o) { PrintWriter w = new PrintWriter(o); w.print(n.toString()); w.close(); }
From source file:Main.java
/** * Print a string representation of the current stack state of all the active threads. *//*from ww w .j ava2 s . c o m*/ public static void printStackTraces() { printStackTraces(new PrintWriter(new OutputStreamWriter(System.err))); }
From source file:com.tera.common.util.ExceptionUtil.java
/** * Simplified version of getting stacktracer from {@link Throwable} For * advanced use - see {@link org.apache.commons.lang.exception.ExceptionUtils} * //from ww w . j av a 2 s . co m * @param throwable * @return */ public static String getStackTrace(Throwable throwable) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); throwable.printStackTrace(printWriter); return result.toString(); }
From source file:Main.java
/** * Save the contents of a table to a TSV file * Note: uses toString() on the header cells as well as the data cells. If you've got funny columns, * expect funny behavior//from w ww . j a v a 2 s .c o m * @param table * @param outFile * @throws IOException */ public static void SaveTableAsTSV(JTable table, File outFile) throws IOException { PrintWriter outPW = new PrintWriter(outFile); TableModel tableModel = table.getModel(); TableColumnModel columnModel = table.getColumnModel(); StringBuffer headerLineBuf = new StringBuffer(); for (int i = 0; i < columnModel.getColumnCount(); i++) { if (i > 0) headerLineBuf.append("\t"); headerLineBuf.append(columnModel.getColumn(i).getHeaderValue().toString()); } outPW.println(headerLineBuf.toString()); outPW.flush(); for (int i = 0; i < tableModel.getRowCount(); i++) { StringBuffer lineBuf = new StringBuffer(); for (int j = 0; j < tableModel.getColumnCount(); j++) { if (j > 0) lineBuf.append("\t"); lineBuf.append(tableModel.getValueAt(i, j).toString()); } outPW.println(lineBuf.toString()); outPW.flush(); } outPW.close(); }
From source file:com.autentia.tnt.util.BeanUtils.java
/** * Devuelve la pila de una excepcion/*from w w w . j a v a 2 s . c om*/ * @param ex la excepcion * @return la pila de la excepcion */ public static String getErrorDesc(Throwable ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); //NOSONAR return sw.toString(); }