List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:edu.iu.daal_kmeans.regroupallgather.KMUtil.java
public static void storeCentroids(Configuration configuration, String cenDir, Table<DoubleArray> cenTable, int cenVecSize, String name) throws IOException { String cFile = cenDir + File.separator + "out" + File.separator + name; Path cPath = new Path(cFile); LOG.info("centroids path: " + cPath.toString()); FileSystem fs = FileSystem.get(configuration); fs.delete(cPath, true);//from w w w .jav a2s . c om FSDataOutputStream out = fs.create(cPath); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); int linePos = 0; int[] idArray = cenTable.getPartitionIDs().toArray(new int[0]); IntArrays.quickSort(idArray); for (int i = 0; i < idArray.length; i++) { Partition<DoubleArray> partition = cenTable.getPartition(idArray[i]); for (int j = 0; j < partition.get().size(); j++) { linePos = j % cenVecSize; if (linePos == (cenVecSize - 1)) { bw.write(partition.get().get()[j] + "\n"); } else if (linePos > 0) { // Every row with vectorSize + 1 length, // the first one is a count, // ignore it in output bw.write(partition.get().get()[j] + " "); } } } bw.flush(); bw.close(); }
From source file:jsonconverter.createandwrite.JSONFileWriter.java
public void createFile(String name, String JSONFolderPath) { try {/*from ww w .ja v a 2 s . c om*/ File file = new File(JSONFolderPath, name + ".txt"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write(obj.toString()); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.silverpeas.dbbuilder.DBBuilder.java
private static DBXmlDocument loadMasterContribution(File dirXml) throws IOException, AppBuilderException { DBXmlDocument destXml = new DBXmlDocument(dirXml, MASTER_DBCONTRIBUTION_FILE); destXml.setOutputEncoding(CharEncoding.UTF_8); if (!destXml.getPath().exists()) { destXml.getPath().createNewFile(); BufferedWriter destXmlOut = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(destXml.getPath(), false), Charsets.UTF_8)); try {/*from ww w.j a va 2s .c o m*/ destXmlOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); destXmlOut.newLine(); destXmlOut.write("<allcontributions>"); destXmlOut.newLine(); destXmlOut.write("</allcontributions>"); destXmlOut.newLine(); destXmlOut.flush(); } finally { IOUtils.closeQuietly(destXmlOut); } } destXml.load(); return destXml; }
From source file:com.t_oster.visicut.misc.Helper.java
public static void installInkscapeExtension() throws FileNotFoundException, IOException { File src = new File(getVisiCutFolder(), "inkscape_extension"); if (!src.exists() || !src.isDirectory()) { throw new FileNotFoundException("Not a directory: " + src); }/* w ww . j a v a2 s. c o m*/ String profile_path = System.getenv("INKSCAPE_PORTABLE_PROFILE_DIR"); if (profile_path == null) { profile_path = System.getenv("INKSCAPE_PROFILE_DIR"); } File trg; if (profile_path != null) { trg = new File(profile_path); } else { if (isWindows()) { trg = new File(System.getenv("AppData")); } else { trg = new File(FileUtils.getUserDirectory(), ".config"); } } trg = new File(new File(trg, "inkscape"), "extensions"); if (!trg.exists() && !trg.mkdirs()) { throw new FileNotFoundException("Can't create directory: " + trg); } for (File f : src.listFiles()) { if ("visicut_export.py".equals(f.getName())) { File target = new File(trg, "visicut_export.py"); BufferedReader r = new BufferedReader(new FileReader(f)); BufferedWriter w = new BufferedWriter(new FileWriter(target)); String line = r.readLine(); while (line != null) { if ("VISICUTDIR=\"\"".equals(line)) { line = "VISICUTDIR=r\"" + getVisiCutFolder().getAbsolutePath() + "\""; } w.write(line); w.newLine(); line = r.readLine(); } w.flush(); w.close(); r.close(); } else if (f.getName().toLowerCase().endsWith("inx") || f.getName().toLowerCase().endsWith("py")) { FileUtils.copyFileToDirectory(f, trg); } } }
From source file:bftsmart.tom.util.RSAKeyPairGenerator.java
private void saveToFile(int id, PublicKey puk, PrivateKey prk) throws Exception { String path = "config" + System.getProperty("file.separator") + "keys" + System.getProperty("file.separator"); BufferedWriter w = new BufferedWriter(new FileWriter(path + "publickey" + id, false)); w.write(getKeyAsString(puk));/*from ww w . j a v a 2s . c om*/ w.flush(); w.close(); w = new BufferedWriter(new FileWriter(path + "privatekey" + id, false)); w.write(getKeyAsString(prk)); w.flush(); w.close(); }
From source file:model.settings.ReadSettings.java
/** * reads text from a configuration file; if is configuration file * is not valid, return null; otherwise return configuration line. * /*from w w w.jav a 2 s .c om*/ * @param _path from which _path is red. * @return the text read form file @ _path. * * @throws IOException is thrown in case of error. */ public static void changeOption(final String _operation, final String _newValue) throws IOException { //create Reader FileReader fr = new FileReader(PROGRAM_SETTINGS_LOCATION); BufferedReader br = new BufferedReader(fr); String sumLine = ""; String currentLine = ""; boolean found = false; currentLine = br.readLine(); while (currentLine != null) { if (!found) { sumLine += currentLine + "\n"; } else { found = !found; sumLine += _newValue + "\n"; } // if the current line is the identifier of the current // operation that has to be changed. if (currentLine != null && currentLine.equals(_operation)) { found = true; } currentLine = br.readLine(); } //close reader br.close(); fr.close(); FileWriter fw = new FileWriter(PROGRAM_SETTINGS_LOCATION); BufferedWriter bw = new BufferedWriter(fw); bw.write(sumLine); bw.flush(); bw.close(); fw.close(); }
From source file:com.github.marabou.properties.PropertiesLoader.java
private void writeUserProperties(Properties userProperties) throws IOException { BufferedWriter userConf = createWriter(pathHelper.getUserPropertiesFilePath()); userProperties.store(userConf, null); userConf.flush(); userConf.close();// w w w . j a v a 2 s . com }
From source file:com.mindcognition.mindraider.install.Installer.java
/** * Fix URIs - remove dvorka & savant in order to replace it with user's * hostname.//from w w w. j av a2 s .c o m * * @param filename * the filename * @todo replace reading/closing file with commons-io functions */ public static void fixUris(String filename) { StringBuffer stringBuffer = new StringBuffer(); BufferedReader in = null; try { // try to start reading in = new BufferedReader(new FileReader(new File(filename))); String line; while ((line = in.readLine()) != null) { stringBuffer.append(line); stringBuffer.append("\n"); } } catch (IOException e) { logger.debug(Messages.getString("Installer.unableToReadFile", filename), e); } finally { if (in != null) { try { in.close(); } catch (IOException e1) { logger.debug(Messages.getString("Installer.unableToCloseReader")); } } } // file successfuly loaded - now replace strings String old = stringBuffer.toString(); if (old != null) { String replacement = "http://" + profileHostname + "/e-mentality/mindmap#" + profileUsername; old = old.replaceAll("http://dvorka/e-mentality/mindmap#dvorka", replacement); old = old.replaceAll("http://dvorka/", "http://" + profileHostname + "/"); old = old.replaceAll("http://savant/", "http://" + profileHostname + "/"); // logger.debug(old+"\n"); } // write it back BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(filename)); out.write(old); } catch (Exception e) { logger.debug(Messages.getString("Installer.unableToWriteFixedFile", filename), e); } finally { if (out != null) { try { out.flush(); out.close(); } catch (IOException e1) { logger.debug(Messages.getString("Installer.unableToCloseFile", filename), e1); } } } }
From source file:hudson.plugins.chainreactorclient.ChainReactorInvalidServerException.java
protected void sendBuildInfo(BufferedWriter writer) throws IOException { writer.write(this.json); writer.flush(); }
From source file:org.ngrinder.monitor.service.MonitorClientSerivce.java
private void flushAndClose(BufferedWriter bw) { try {// w w w . java 2 s . c o m bw.flush(); } catch (IOException e) { LOGGER.error("While running flushAndClose() in MonitorClientSerivce, the error occurs."); LOGGER.error("Details : ", e); } IOUtils.closeQuietly(bw); }