List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:org.mashupmedia.service.MapperManagerImpl.java
@Override public void writeStartRemoteMusicLibraryXml(long libraryId, LibraryType libraryType) throws Exception { File file = FileHelper.getLibraryXmlFile(libraryId); FileWriter writer = new FileWriter(file, false); writer.write("<?xml version=\"1.0\" ?>"); writer.write("<library type=\"" + libraryType.name().toLowerCase() + "\">"); writer.close(); }
From source file:com.photon.maven.plugins.android.standalonemojos.UpdateBuildInfoMojo.java
private void writeBuildInfo(boolean isBuildSuccess) throws MojoExecutionException { try {/*from w ww . j a v a 2 s . c om*/ PluginUtils pu = new PluginUtils(); BuildInfo buildInfo = new BuildInfo(); List<String> envList = pu.csvToList(environmentName); buildInfo.setBuildNo(nextBuildNo); buildInfo.setTimeStamp(getTimeStampForDisplay(currentDate)); if (isBuildSuccess) { buildInfo.setBuildStatus("SUCCESS"); } else { buildInfo.setBuildStatus("FAILURE"); } buildInfo.setBuildName(apkFileName); buildInfo.setDeliverables(deliverable); buildInfo.setEnvironments(envList); buildInfoList.add(buildInfo); Gson gson = new Gson(); FileWriter writer = new FileWriter(buildInfoFile); gson.toJson(buildInfoList, writer); writer.close(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:de.xirp.ui.util.HelpManager.java
/** * Writes the navigation HTML-file. The links for existing plugins * are added to the existing links of the standard program help. */// ww w . j a v a2 s . c o m private void createNavigationHTML() { StringBuilder naviPage = new StringBuilder(); naviPage.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">") //$NON-NLS-1$ .append(Constants.LINE_SEPARATOR); naviPage.append("<HTML>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ naviPage.append("<HEAD>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ naviPage.append(" <META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=windows-1252\">") //$NON-NLS-1$ .append(Constants.LINE_SEPARATOR); naviPage.append(" <TITLE>nav frame</TITLE>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ naviPage.append("</HEAD>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ naviPage.append("<BODY>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ // naviPage.append("<UL>"+Constants.LINE_SEPARATOR); createXirpLinks(naviPage); createPluginLinks(naviPage); // naviPage.append("</UL>"+Constants.LINE_SEPARATOR); naviPage.append("</BODY>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ naviPage.append("</HTML>").append(Constants.LINE_SEPARATOR); //$NON-NLS-1$ File f = new File(Constants.HELP_DIR + File.separator + "nav_frame.html"); //$NON-NLS-1$ try { FileWriter fw = new FileWriter(f); fw.write(naviPage.toString()); fw.close(); } catch (FileNotFoundException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } catch (IOException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } }
From source file:net.itransformers.idiscover.v2.core.listeners.node.GraphmlFileLogGroovyDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); File graphmlDir = new File(baseDir, graphmlDirName); if (!graphmlDir.exists()) graphmlDir.mkdir();// w w w. j a v a2 s. c om String deviceName = discoveryResult.getNodeId(); if (deviceName == null) return; //This is a case of a subnetKind of a node or other nodes without nodeId. DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult .getDiscoveredData("deviceData"); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JaxbMarshalar.marshal(discoveredDeviceData, out, "DiscoveredDevice"); } catch (JAXBException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } StringReader reader = new StringReader(out.toString()); StringWriter graphmlWriter = new StringWriter(); transformRawDataToGraphml(reader, graphmlWriter); try { final String fileName = "node-" + deviceName + ".graphml"; // String fullFileName = path + File.separator + fileName; final File nodeFile = new File(graphmlDir, fileName); //System.out.println(new String(graphmlWriter.toString())); String graphml; graphml = new XmlFormatter().format(graphmlWriter.toString()); FileUtils.writeStringToFile(nodeFile, graphml); File undirectedGraphmls = new File(graphmlDir.getParent(), "undirected" + ".graphmls"); if (!undirectedGraphmls.exists()) { undirectedGraphmls.createNewFile(); } FileWriter writer = new FileWriter(undirectedGraphmls, true); writer.append(String.valueOf(fileName)).append("\n"); writer.close(); } catch (IOException e) { logger.debug("Unformated xml is not in correct format: \n" + graphmlWriter.toString()); e.printStackTrace(); } catch (ParserConfigurationException e) { logger.debug("Unformated xml is not in correct format: \n" + graphmlWriter.toString()); e.printStackTrace(); } catch (SAXException e) { logger.debug("Unformated xml is not in correct format: \n" + graphmlWriter.toString()); e.printStackTrace(); } }
From source file:com.ut.healthelink.service.hl7toTxt.java
public String TranslateHl7toTxt(String fileLocation, String fileName, int orgId) throws Exception { Organization orgDetails = organizationmanager.getOrganizationById(orgId); fileSystem dir = new fileSystem(); dir.setDir(orgDetails.getcleanURL(), "templates"); String templatefileName = orgDetails.getparsingTemplate(); URLClassLoader loader = new URLClassLoader( new URL[] { new URL("file://" + dir.getDir() + templatefileName) }); // Remove the .class extension Class cls = loader.loadClass(templatefileName.substring(0, templatefileName.lastIndexOf('.'))); Constructor constructor = cls.getConstructor(); Object HL7Obj = constructor.newInstance(); Method myMethod = cls.getMethod("HL7toTxt", new Class[] { File.class }); /* Get the uploaded HL7 File */ fileLocation = fileLocation.replace("/Applications/bowlink/", "").replace("/home/bowlink/", "") .replace("/bowlink/", ""); dir.setDirByName(fileLocation);/*from ww w .j a va2s.c o m*/ File hl7File = new File(dir.getDir() + fileName + ".hr"); /* Create the output file */ String newfileName = new StringBuilder() .append(hl7File.getName().substring(0, hl7File.getName().lastIndexOf("."))).append(".") .append("txt").toString(); File newFile = new File(dir.getDir() + newfileName); if (newFile.exists()) { try { if (newFile.exists()) { int i = 1; while (newFile.exists()) { int iDot = newfileName.lastIndexOf("."); newFile = new File(dir.getDir() + newfileName.substring(0, iDot) + "_(" + ++i + ")" + newfileName.substring(iDot)); } newfileName = newFile.getName(); newFile.createNewFile(); } else { newFile.createNewFile(); } } catch (IOException e) { e.printStackTrace(); } } else { newFile.createNewFile(); newfileName = newFile.getName(); } FileWriter fw = new FileWriter(newFile, true); /* END */ String fileRecords = (String) myMethod.invoke(HL7Obj, new Object[] { hl7File }); fw.write(fileRecords); fw.close(); return newfileName; }
From source file:com.xpn.xwiki.plugin.svg.SVGPlugin.java
public byte[] getSVGImage(int hashCode, String content, String extension, int height, int width) throws IOException, SVGConverterException { File dfile = getTempFile(hashCode, "svg"); if (!dfile.exists()) { FileWriter fwriter = new FileWriter(dfile); fwriter.write(content);//from w w w . ja v a 2 s. c o m fwriter.flush(); fwriter.close(); } File ofile = getTempFile(hashCode, extension); // TODO implement conversion HERE SVGConverter conv = new SVGConverter(); // TODO PNG ONLY conv.setDestinationType(DestinationType.PNG); conv.setDst(ofile); conv.setHeight(height); conv.setWidth(width); String[] sources = { dfile.getAbsolutePath() }; conv.setSources(sources); conv.execute(); FileInputStream fis = new FileInputStream(ofile); byte[] result = new byte[(int) ofile.length()]; try { fis.read(result); } finally { IOUtils.closeQuietly(fis); } return result; }
From source file:de.joinout.criztovyl.tools.json.JSONFile.java
/** * Writes the JSON data to the file./*from www .j a v a2s . com*/ */ public void write() { try { //Create file if not exists path.touch(); //Create writer final FileWriter fw = new FileWriter(path.getFile()); //Write fw.write(data); //Flush 'n' close fw.flush(); fw.close(); } catch (final IOException e) { logger.catching(e); } }
From source file:org.powertac.producer.windfarm.WindFarmTest.java
@Test public void dataGenerateXML() throws IOException { double[] x = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; double[] y = { 0, -66, -166, -288, -473, -709, -1000, -1316, -1651, -1860, -1968, -2000, -2000, -2000, -2000, -2000, -2000, -2000, -2000, -2000, -2000, -2000, -2000 }; Curve c = new Curve(x, y); c.setCustomLastValue(0);//from www . jav a2s. c om WindFarm wf = new WindFarm(); WindTurbine wt = new WindTurbine(22, 0.01, -2000, 80, c); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); wf.addWindTurbine(wt); new File("data/").mkdir(); FileWriter fw = new FileWriter("data/wind-farm.xml"); XStream xstream = new XStream(); xstream.autodetectAnnotations(true); xstream.toXML(wf, fw); fw.close(); }
From source file:com.bekwam.examples.javafx.oldscores2.data.SettingsDAOImpl.java
@Override public void save() throws IOException { if (logger.isDebugEnabled()) { logger.debug("[SAVE] saving " + getAbsolutePath()); }//from w ww .j a v a2s. c om FileWriter fw = new FileWriter(getAbsolutePath()); Properties props = new Properties(); props.setProperty("oldscores.roundUp", String.valueOf(settings.getRoundUp())); props.store(fw, ""); fw.close(); markForRefresh(); }
From source file:com.oneops.util.ReliableExecutor.java
private void writeToFile(I param) { try {//from w ww . ja va 2s . c o m if (name != null) { logger.warn(name + " execution failed. storing data to a file."); logger.warn(name + " - Active workers count : " + executors.getActiveCount()); } checkBacklog(); FileWriter wr = new FileWriter(getFileName(param)); gson.toJson(param, wr); wr.close(); } catch (Exception e) { logger.error(e.getMessage()); logger.debug(e.getMessage(), e); } }