List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:com.urremote.classifier.common.ExceptionHandler.java
private void writeToFile(String stacktrace, String filename) { try {// w ww . j a v a 2s. c om File outputFile = new File(Constants.PATH_SD_CARD_APP_LOC + File.separator + filename); if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Log.e(Constants.TAG, "Unable to write stacktrace to file. External media not mounted!"); return; } Log.v(Constants.TAG, "Output Trace File:" + outputFile); if (!outputFile.getParentFile().exists()) { if (!outputFile.getParentFile().mkdirs()) { Log.e(Constants.TAG, "Unable to create log file directory:\n" + outputFile.getParentFile() + "\nCaused when writing stack to file:\n" + stacktrace); } } if (!outputFile.exists()) { if (!outputFile.createNewFile()) { Log.e(Constants.TAG, "Unable to create log file:\n" + outputFile.getParentFile() + "\nCaused when writing stack to file:\n" + stacktrace); } } BufferedWriter bos = new BufferedWriter(new FileWriter(outputFile)); bos.write(stacktrace); bos.flush(); bos.close(); Log.e(Constants.TAG, stacktrace); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.abc4trust.cryptoEngine.uprove.util.UProveLauncher.java
public int stop() { // System.out.println("UProveLauncher.stop instance : " + this + " : " + launchName + " - port : " + launchPort + " - is stopped == " + stopped + " - process : " + this.uproveProcess); if (this.uproveProcess != null) { try {/*from ww w.j a v a 2 s . c o m*/ OutputStream outputStream = this.uproveProcess.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); BufferedWriter out = new BufferedWriter(outputStreamWriter); out.newLine(); out.flush(); int exitCode = -1; boolean done = false; while (!done) { try { exitCode = this.uproveProcess.exitValue(); done = true; break; } catch (IllegalThreadStateException ex) { // System.out.println("process not terminated"); this.waitFor(1); } } this.debugOutputCollector.stop(); this.debugOutput.interrupt(); this.uproveProcess = null; return exitCode; } catch (IOException ex) { throw new RuntimeException(ex); } } if (this.startCalled) { return Integer.MIN_VALUE; } else { return 0; } }
From source file:com.android.internal.http.multipart.MultipartTest.java
public void testParts() throws Exception { StringBuffer filebuffer = new StringBuffer(); String filepartStr = "this is file part"; filebuffer.append(filepartStr);//from w w w. j a v a 2 s . c o m File upload = File.createTempFile("Multipart", "test"); FileWriter outFile = new FileWriter(upload); BufferedWriter out = new BufferedWriter(outFile); try { out.write(filebuffer.toString()); out.flush(); } finally { out.close(); } Part[] parts = new Part[3]; parts[0] = new StringPart("stringpart", "PART1!!"); parts[1] = new FilePart(upload.getName(), upload); parts[2] = new StringPart("stringpart", "PART2!!"); MultipartEntity me = new MultipartEntity(parts); ByteArrayOutputStream os = new ByteArrayOutputStream(); me.writeTo(os); Header h = me.getContentType(); String boundry = EncodingUtils.getAsciiString(me.getMultipartBoundary()); StringBuffer contentType = new StringBuffer("multipart/form-data"); contentType.append("; boundary="); contentType.append(boundry); assertEquals("Multipart content type error", contentType.toString(), h.getValue()); final String CRLF = "\r\n"; StringBuffer output = new StringBuffer(); output.append("--"); output.append(boundry); output.append(CRLF); output.append("Content-Disposition: form-data; name=\"stringpart\""); output.append(CRLF); output.append("Content-Type: text/plain; charset=US-ASCII"); output.append(CRLF); output.append("Content-Transfer-Encoding: 8bit"); output.append(CRLF); output.append(CRLF); output.append("PART1!!"); output.append(CRLF); output.append("--"); output.append(boundry); output.append(CRLF); output.append("Content-Disposition: form-data; name=\""); output.append(upload.getName()); output.append("\"; filename=\""); output.append(upload.getName()); output.append("\""); output.append(CRLF); output.append("Content-Type: application/octet-stream; charset=ISO-8859-1"); output.append(CRLF); output.append("Content-Transfer-Encoding: binary"); output.append(CRLF); output.append(CRLF); output.append(filepartStr); output.append(CRLF); output.append("--"); output.append(boundry); output.append(CRLF); output.append("Content-Disposition: form-data; name=\"stringpart\""); output.append(CRLF); output.append("Content-Type: text/plain; charset=US-ASCII"); output.append(CRLF); output.append("Content-Transfer-Encoding: 8bit"); output.append(CRLF); output.append(CRLF); output.append("PART2!!"); output.append(CRLF); output.append("--"); output.append(boundry); output.append("--"); output.append(CRLF); // System.out.print(output.toString()); assertEquals("Multipart content error", output.toString(), os.toString()); // System.out.print(os.toString()); }
From source file:es.sotileza.plugin.utils.Utilidades.java
public static void paintMaestroManager(String file, List<String> tr1, List<String> tr2, List<String> tr3, ArquetipoVO arq) throws IOException { FileWriter output = new FileWriter(file); BufferedWriter writer = new BufferedWriter(output); writer.write("package " + arq.getPakete() + ".business.manager;\n\r"); writer.write("import " + arq.getPakete() + ".business.vo.*;"); writer.write("import " + arq.getPakete() + ".business.dao.*;"); writer.write("import java.util.List;"); writer.write("import org.apache.commons.logging.Log;"); writer.write("import org.apache.commons.logging.LogFactory;"); writer.write("\n\r"); writer.write("/**\n * Clase Manager - Maestros\n */"); writer.write("public class MaestrosManager {\n\r"); writer.write("\tprivate static Log log = LogFactory.getFactory().getInstance(MaestrosManager.class);"); for (String i : tr1) writer.write(i + "\n"); for (String i : tr2) writer.write(i + "\n"); for (String i : tr3) writer.write(i + "\n"); writer.write("}"); System.out.println("Generado el fichero: " + file); writer.flush(); }
From source file:com.imaginary.home.controller.RelayTest.java
@Before public void setUp() throws IOException { File f = new File("target/iha"); if (!f.exists()) { //noinspection ResultOfMethodCallIgnored f.mkdir();/*from w w w . ja v a 2 s .c o m*/ } f = new File(HomeController.CONFIG_FILE); if (!f.exists()) { HashMap<String, Object> cfg = new HashMap<String, Object>(); cfg.put("name", "Relay Test"); ArrayList<Map<String, Object>> systems = new ArrayList<Map<String, Object>>(); HashMap<String, Object> hue = new HashMap<String, Object>(); HashMap<String, Object> auth = new HashMap<String, Object>(); String hueIp = System.getProperty("ip"); String hueAccessKey = System.getProperty("accessKey"); auth.put("ipAddress", hueIp); auth.put("accessKey", hueAccessKey); hue.put("cname", Hue.class.getName()); hue.put("id", "1"); hue.put("authenticationProperties", auth); hue.put("customProperties", new HashMap<String, Object>()); systems.add(hue); cfg.put("systems", systems); cfg.put("services", new ArrayList<Map<String, Object>>()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f))); writer.write((new JSONObject(cfg)).toString()); writer.newLine(); writer.flush(); writer.close(); } }
From source file:playground.christoph.evacuation.analysis.AgentsReturnHomeWriter.java
/** * Writes the gathered data tab-separated into a text file. * * @param filename The name of a file where to write the gathered data. */// w ww . ja v a 2 s .co m public void write(final String filename, Map<String, AtomicInteger[]> data) { try { BufferedWriter bufferedWriter = IOUtils.getBufferedWriter(filename); write(bufferedWriter, data); bufferedWriter.flush(); bufferedWriter.close(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:gr.auth.ee.lcs.evaluators.FileLogger.java
/** * FileLogger constructor./* ww w . j a va 2 s .c o m*/ * * @param filename * the filename of the file where log will be output. * @param evaluator * the evaluator which we are going to output. */ public FileLogger(final String filename, final ILCSMetric evaluator) { file = storeDirectory + "/" + filename + ".txt"; actualEvaluator = evaluator; try { final FileWriter fstream = new FileWriter(file, false); final BufferedWriter buffer = new BufferedWriter(fstream); buffer.write(""); buffer.flush(); buffer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.jbrisbin.vpc.jobsched.patch.PatchMessageHandler.java
public void handleMessage(final PatchMessage msg) { if (null != msg.getFile()) { // Read original file List<String> original = new ArrayList<String>(); File originalFile = new File(msg.getFile()); try {// w ww. ja v a 2s. c o m BufferedReader reader = new BufferedReader(new FileReader(originalFile)); String line = null; while (null != (line = reader.readLine())) { original.add(line); } reader.close(); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } if (log.isDebugEnabled()) { log.debug("Patching original file: " + original); } // Patch it Patch patch = DiffUtils.parseUnifiedDiff(msg.getDiff()); try { List<String> updated = (List<String>) DiffUtils.patch(original, patch); File tmp = File.createTempFile("patcher_", "patched"); BufferedWriter writer = new BufferedWriter(new FileWriter(tmp)); for (String line : updated) { writer.write(line + "\n"); } writer.flush(); writer.close(); // Backup existing file File basedir = originalFile.getParentFile(); if (basedir.canWrite()) { File backup = new File(originalFile.getParentFile(), originalFile.getName() + ".bkp." + fmt.format(Calendar.getInstance().getTime())); originalFile.renameTo(backup); // Replace with patched version tmp.renameTo(originalFile); } } catch (PatchFailedException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } } }
From source file:playground.christoph.evacuation.analysis.AgentsReturnHomeWriter.java
/** * Writes the gathered data tab-separated into a text file. * * @param filename The name of a file where to write the gathered data. *//*w w w . j ava 2 s . c o m*/ public void write(String fileName, Map<Id, ActivityInfo> activityInfo, Map<Id, String> legModes) { try { BufferedWriter writer = IOUtils.getBufferedWriter(fileName); write(writer, activityInfo, legModes); writer.flush(); writer.close(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:m3umaker.exFiles.java
public void genFile(String Path, String M3UfileName, List Files) { try {//from w w w. j a v a 2s.c o m BufferedWriter out = new BufferedWriter(new FileWriter(Path + "\\" + M3UfileName + ".m3u", true)); for (int i = 0; i < Files.size(); i++) { out.write(Files.get(i).toString()); out.newLine(); } out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }