List of usage examples for java.io PrintWriter flush
public void flush()
From source file:Main.java
/** * Copied from "android.util.Log.getStackTraceString()" in order to avoid usage of Android stack * in unit tests.//from ww w. j av a 2s . c o m * * @return Stack trace in form of String */ static String getStackTraceString(Throwable tr) { if (tr == null) { return ""; } // This is to reduce the amount of log spew that apps do in the non-error // condition of the network being unavailable. Throwable t = tr; while (t != null) { if (t instanceof UnknownHostException) { return ""; } t = t.getCause(); } StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); tr.printStackTrace(pw); pw.flush(); return sw.toString(); }
From source file:Main.java
/** * <p>//from w ww. j a va2 s . c o m * Print the full stack trace of a <code>Throwable</code> object into a * string buffer and return the corresponding string. * </p> */ public static String printStackTrace(Throwable t) { java.io.StringWriter strWriter = new java.io.StringWriter(); java.io.PrintWriter prWriter = new java.io.PrintWriter(strWriter); t.printStackTrace(prWriter); prWriter.flush(); return strWriter.toString(); }
From source file:Main.java
public static String getStackTrace(Throwable t) { StringWriter stringWritter = new StringWriter(); PrintWriter printWritter = new PrintWriter(stringWritter, true); t.printStackTrace(printWritter);//from w w w . j a va2 s.c o m printWritter.flush(); stringWritter.flush(); return stringWritter.toString(); }
From source file:Main.java
public static Boolean writeToSDFile(String directory, String file_name, String text) { // Find the root of the external storage. // See/*from w w w .ja v a2s.co m*/ // http://developer.android.com/guide/topics/data/data-storage.html#filesExternal File root = Environment.getExternalStorageDirectory(); // See // http://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder File dir = new File(root.getAbsolutePath() + "/" + directory); dir.mkdirs(); File file = new File(dir, file_name); try { FileOutputStream f = new FileOutputStream(file); PrintWriter pw = new PrintWriter(f); pw.println(text); pw.flush(); pw.close(); f.close(); // Log.v(TAG, "file written to sd card"); return true; } catch (FileNotFoundException e) { e.printStackTrace(); // Log.i(TAG, "******* File not found. Did you" + // " add a WRITE_EXTERNAL_STORAGE permission to the manifest?"); return false; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:com.jmu.util.ResponseJsonUtils.java
public static void writeJSON(PrintWriter wirter, AjaxResponse json) { wirter.print(JSON.toJSONString(json)); wirter.flush(); wirter.close();//from w w w .j a v a 2s.co m }
From source file:Main.java
public static void writeToExternalFile(String data, String logTag, String fileName) { if (!isExternalStorageWritable()) { Log.e(logTag, "failed to find external storage"); } else {//from w w w . ja v a2 s . c o m File path = Environment.getExternalStorageDirectory(); File dir = new File(path.getAbsolutePath() + "/SDNController"); if (!dir.isDirectory()) { if (!dir.mkdirs()) { Log.e(logTag, "sdn directory can not be created"); return; } } File file = new File(dir, fileName); try { FileOutputStream f = new FileOutputStream(file, true); PrintWriter pw = new PrintWriter(f); pw.println(data); pw.flush(); pw.close(); f.close(); } catch (FileNotFoundException e) { Log.e(logTag, "can not find indicated file"); e.printStackTrace(); } catch (IOException e) { Log.e(logTag, "failed to write SDNController/result.txt"); e.printStackTrace(); } } }
From source file:mobisocial.musubi.ui.util.FeedHTML.java
public static void writeFooter(FileOutputStream fo) { PrintWriter w = new PrintWriter(fo); w.print("</body>"); w.print("</html>"); w.flush(); }
From source file:com.abid_mujtaba.bitcoin.tracker.data.Data.java
public static void append(String line) throws DataException // Append line to data file. { File file = data_file();/*from w ww . ja va 2 s. com*/ try { FileOutputStream fos = new FileOutputStream(file, true); // We pass in true so that the text is appended PrintWriter pw = new PrintWriter(fos); pw.println(line); pw.flush(); pw.close(); fos.close(); } catch (FileNotFoundException e) { throw new DataException("Error while writing to file.", e); } catch (IOException e) { throw new DataException("Error while writing to file.", e); } }
From source file:Main.java
public static boolean appendFile(String strThrift, String filePath) { PrintWriter out = null; try {/*w w w . j a va2s .com*/ out = new PrintWriter(new BufferedWriter(new FileWriter(filePath, true))); out.println(strThrift); out.flush(); out.close(); } catch (IOException e) { return false; } return true; }
From source file:com.talis.entity.TestUtils.java
public static void printQuads(Iterable<Quad> quads) { PrintWriter out = new PrintWriter(System.out); for (Quad quad : quads) { OutputLangUtils.output(out, quad, null, null); }//from w ww .j ava 2s.co m out.flush(); }