List of usage examples for java.io BufferedWriter close
@SuppressWarnings("try") public void close() throws IOException
From source file:com.tintin.devcloud.web.FileResource.java
@POST public String getStatus(@FormParam("path") String fileName, @FormParam("content") String content) { String path = null;/*ww w. jav a 2 s . c om*/ try { System.out.println(fileName); System.out.println(content); File file = new File(fileName); File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } path = file.getAbsolutePath(); BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); out.write(content); System.out.println(content); out.close(); } catch (Exception e) { return e.toString(); } return path; }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
private static void writeSimilarityToTextFile(double[][] similarities) { try {//w w w . j a va2 s . co m FileOutputStream fos = new FileOutputStream(outputFile); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos)); for (int i = 0; i < similarities.length; i++) { for (int j = 0; j < similarities[0].length; j++) { writer.write(String.format("%f,", similarities[i][j])); } writer.newLine(); } writer.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:tomekkup.helenos.web.servlet.view.CsvView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Disposition", "attachment; filename=\"" + (String) model.get("key") + "_" + (String) model.get("key") + ".csv\""); BufferedWriter writer = new BufferedWriter(response.getWriter()); //myDbData = (Whatever) modelMap.get("modelKey"); //some kind of loop {writer.write(myDbData csv row); writer.newLine(); } writer.flush();//from w w w.j a v a 2 s. c o m writer.close(); }
From source file:com.highcharts.export.util.SVGCreator.java
private void writeFile(File file, String content) throws IOException { FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); try {//from w ww. j a v a 2s .c o m bw.write(content); } finally { bw.close(); fw.close(); } }
From source file:de.siemens.quantarch.bugs.impl.BugzillaTracker.java
private void writeIntoConfigFile(File file, String bugzillaURL, String proxyServer, int proxyPort) throws IOException { // if file doesn't exists, then create it if (!file.exists()) { file.createNewFile();// w w w. java2s.c o m } // check if proxy configuration is needed String finalString = null; if (StringUtils.isBlankOrNull(proxyServer)) { finalString = CONFIG_FILE_WITHOUT_PROXY.replace("$BUGZILLA_URL$", bugzillaURL); } else { finalString = CONFIG_FILE_WITH_PROXY.replace("$BUGZILLA_URL$", bugzillaURL).replace("$PROXY_HOST$", proxyServer + ":" + proxyPort); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(finalString); bw.close(); }
From source file:com.vmanolache.mqttpolling.Polling.java
private void sendPost() throws UnsupportedEncodingException, JSONException { try {/* w ww . j a v a 2 s . c o m*/ String url = "http://localhost:8080/notifications"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); HttpURLConnection connection = (HttpURLConnection) obj.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestMethod("POST"); /** * POSTing * */ OutputStream os = connection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(getQuery()); // should be fine if my getQuery is encoded right yes? writer.flush(); writer.close(); os.close(); connection.connect(); int status = connection.getResponseCode(); System.out.println(status); } catch (IOException ex) { Logger.getLogger(Polling.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:eionet.gdem.dcm.conf.DcmProperties.java
public void setDbParams(String url, String user, String psw) throws DCMException { String filePath = Properties.appHome + File.separatorChar + "gdem.properties"; try {/*ww w .j a va 2 s.co m*/ BufferedReader reader = new BufferedReader(new FileReader(filePath)); String line = null; StringBuffer st = new StringBuffer(); while ((line = reader.readLine()) != null) { // process the line line = findSetProp(line, "db.url", url); line = findSetProp(line, "db.user", user); line = findSetProp(line, "db.pwd", psw); st.append(line); st.append("\n"); } BufferedWriter out = new BufferedWriter(new FileWriter(filePath)); out.write(st.toString()); out.close(); } catch (IOException e) { LOGGER.error("Saving database parameters failed!", e); e.printStackTrace(); throw new DCMException(BusinessConstants.EXCEPTION_PARAM_DB_FAILED); } }
From source file:eionet.gdem.dcm.conf.DcmProperties.java
public void setLdapParams(String url, String context, String userDir, String attrUid) throws DCMException { String filePath = Properties.appHome + File.separatorChar + "eionetdir.properties"; try {//from w w w . ja v a 2s . c o m BufferedReader reader = new BufferedReader(new FileReader(filePath)); String line = null; StringBuffer st = new StringBuffer(); while ((line = reader.readLine()) != null) { // process the line line = findSetProp(line, "ldap.url", url); line = findSetProp(line, "ldap.context", context); line = findSetProp(line, "ldap.user.dir", userDir); line = findSetProp(line, "ldap.attr.uid", attrUid); st.append(line); st.append("\n"); } BufferedWriter out = new BufferedWriter(new FileWriter(filePath)); out.write(st.toString()); out.close(); } catch (IOException e) { LOGGER.error("Saving ldap parameters failed!", e); e.printStackTrace(); throw new DCMException(BusinessConstants.EXCEPTION_PARAM_LDAP_FAILED); } }
From source file:com.idiro.utils.db.mysql.MySqlUtils.java
public static boolean changeFormatAfterExport(File in, File out, char delimiter, Collection<String> header, Collection<String> quotes) { //We expect that in is a csv file and out a file boolean ok = true; FileChecker fChIn = new FileChecker(in), fChOut = new FileChecker(out); if (!fChIn.isFile()) { logger.error(fChIn.getFilename() + " is not a directory or does not exist"); return false; }/*w w w .jav a 2s .c o m*/ if (fChOut.exists()) { if (fChOut.isDirectory()) { logger.error(fChOut.getFilename() + " is a directory"); return false; } logger.warn(fChOut.getFilename() + " already exists, it will be removed"); String out_str = out.getAbsolutePath(); out.delete(); out = new File(out_str); } BufferedWriter bw = null; BufferedReader br = null; try { bw = new BufferedWriter(new FileWriter(out)); logger.debug("read the file" + in.getAbsolutePath()); br = new BufferedReader(new FileReader(in)); String strLine; if (header != null && !header.isEmpty()) { Iterator<String> it = header.iterator(); String headerLine = it.next(); while (it.hasNext()) { headerLine += delimiter + it.next(); } bw.write(headerLine + "\n"); } //Read File Line By Line while ((strLine = br.readLine()) != null) { bw.write(DataFileUtils.addQuotesToLine( DataFileUtils.getCleanLine(strLine.replace(',', delimiter), delimiter, delimiter), quotes, delimiter) + "\n"); } br.close(); bw.close(); } catch (FileNotFoundException e1) { logger.error(e1.getCause() + " " + e1.getMessage()); logger.error("Fail to read " + in.getAbsolutePath()); ok = false; } catch (IOException e1) { logger.error("Error writting, reading on the filesystem from the directory" + fChIn.getFilename() + " to the file " + fChOut.getFilename()); ok = false; } if (ok) { in.delete(); } return ok; }
From source file:eionet.gdem.dcm.conf.DcmProperties.java
public void setSystemParams(Long qaTimeout, String cmdXGawk) throws DCMException { String filePath = Properties.appHome + File.separatorChar + "gdem.properties"; try {/*from www . j ava2 s. c o m*/ BufferedReader reader = new BufferedReader(new FileReader(filePath)); String line = null; StringBuffer st = new StringBuffer(); while ((line = reader.readLine()) != null) { // process the line line = findSetProp(line, "external.qa.timeout", String.valueOf(qaTimeout)); line = findSetProp(line, "external.qa.command.xgawk", cmdXGawk); st.append(line); st.append("\n"); } BufferedWriter out = new BufferedWriter(new FileWriter(filePath)); out.write(st.toString()); out.close(); Properties.xgawkCommand = cmdXGawk; Properties.qaTimeout = Long.valueOf(qaTimeout); } catch (IOException e) { LOGGER.error("Saving system parameters failed!", e); e.printStackTrace(); throw new DCMException(BusinessConstants.EXCEPTION_PARAM_SYSTEM_FAILED); } }