List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:de.fhg.iais.asc.viewspreview.ViewXmlScanner.java
private void closeFile(FileWriter filewriter) throws IOException { if (this.fileWriter != null) { filewriter.write("</body></html>"); filewriter.close(); this.filecounter++; }/*from w w w. j ava 2 s. c o m*/ }
From source file:org.yestech.lib.io.FileSystemFileDownloadFilterUnitTest.java
@Test public void testDeleteAfterDownload() throws IOException, ServletException { config.addInitParameter("deleteAfterDownload", "true"); filter.init(config);//from www . ja v a2 s .c om String testFileName = "unittest.tst222"; File file = new File(System.getProperty("java.io.tmpdir"), testFileName); FileWriter writer = new FileWriter(file); String text = "testing download with delete"; writer.write(text); writer.flush(); writer.close(); request.setParameter("file", testFileName); filter.doFilter(request, response, chain); assertEquals(text.length(), response.getContentLength()); assertEquals(text, response.getContentAsString()); assertFalse(file.exists()); }
From source file:com.xpn.xwiki.plugin.laszlo.LaszloPlugin.java
public String writeLaszloFile(String name, String laszlocode) throws IOException, XWikiException { File laszloDir = new File(laszloPath); if (!laszloDir.exists()) laszloDir.mkdirs();// ww w . j a va2s . co m String filename = getFileName(name, laszlocode); laszlocode = Util.secureLaszloCode(laszlocode); File dfile = new File(laszloDir, filename); if (!dfile.exists()) { FileWriter fwriter = new FileWriter(dfile); fwriter.write(laszlocode); fwriter.flush(); fwriter.close(); } return filename; }
From source file:org.mashupmedia.service.MapperManagerImpl.java
@Override public void writeEndRemoteMusicLibraryXml(long libraryId) throws Exception { File file = FileHelper.getLibraryXmlFile(libraryId); FileWriter writer = new FileWriter(file, true); writer.write("</library>"); writer.close(); }
From source file:eu.esdihumboldt.hale.doc.util.content.AbstractVelocityContent.java
/** * Generate content from the template and the given context factory. If * called more than once with the same id, the previously generated content * for that id is returned.//from w w w . ja v a2 s . c o m * * @param contentId the content id * @param templateId the template id (there may be multiple templates) * @param contextFactory the context factory, is called once or not at all * @return the content input stream to return in * {@link #getInputStream(String, String, Locale)} * @throws Exception if an error occurs creating the content */ protected InputStream getContentFromTemplate(String contentId, String templateId, Callable<VelocityContext> contextFactory) throws Exception { init(templateId); // creates the template file into the temporary directory // if it doesn't already exist File contentFile = new File(tempDir, templateId + "_" + contentId + ".html"); if (!contentFile.exists()) { // get the template context VelocityContext context = contextFactory.call(); // get the template Template template = ve.getTemplate(templateId + ".vm", "UTF-8"); // write to the file FileWriter fw = new FileWriter(contentFile); template.merge(context, fw); fw.close(); contentFile.deleteOnExit(); } return new FileInputStream(contentFile); }
From source file:hudson.lifecycle.WindowsServiceLifecycle.java
/** * On Windows, hudson.war is locked, so we place a new version under a special name, * which is picked up by the service wrapper upon restart. */// w w w .j a v a 2s . c o m @Override public void rewriteHudsonWar(File by) throws IOException { File rootDir = Hudson.getInstance().getRootDir(); File copyFiles = new File(rootDir, "hudson.copies"); FileWriter w = new FileWriter(copyFiles, true); w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n'); w.close(); }
From source file:de.bley.word.filewriter.WriterFile.java
/** * Schreibt Daten in eine Textdatei.//from w w w . java2 s .com * * @param filepath Pfad der zulesenden Datei. * @param text String, welcher in die Datei geschrieben werden soll. * @param flag Boolean, ob Text angehangen oder ueberschrieben werden soll. * */ @Override public void writeInFile(String filepath, final String text, final boolean flag) { try { final FileWriter writer = new FileWriter(filepath, flag); writer.write(text + System.getProperty("line.separator")); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:luceneprueba.utils.FileParser.java
static public void createFilesFromJSONArray() throws IOException { File dir = new File("files/input"); File[] files = dir.listFiles(); if (files == null) { System.out.println("No existe la carpeta \'input\' dentro de la carpeta files."); return;//from w w w .j av a2 s.c o m } if (files.length == 0) { System.out.println("No hay ningun archivo en la carpeta \'input\' para ser indexado"); return; } BufferedReader br; String fileContent; JSONArray jsonArray = null; JSONParser jsonParser = new JSONParser(); int i = 1; FileWriter datosReviews = null; try { datosReviews = new FileWriter("files/output/datos_reviews.txt"); } catch (IOException ex) { ex.printStackTrace(System.out); } for (File file : files) { if (file.isFile() && file.canRead() && file.getName().endsWith(".txt")) { System.out.println("Leyendo el archivo: " + file.getName()); FileWriter contentReviews; try { br = new BufferedReader(new FileReader(file)); fileContent = br.readLine(); jsonArray = (JSONArray) jsonParser.parse(fileContent); Iterator it = jsonArray.iterator(); DecimalFormat formato = new DecimalFormat("000000"); while (it.hasNext()) { JSONObject json = (JSONObject) it.next(); if (json.get("Genre") != null && json.get("Date") != null) { contentReviews = new FileWriter( "files/output/clasificador/review_clasificador_" + formato.format(i) + ".txt"); datosReviews.write(Integer.toString(i) + "_" + (String) json.get("Date") + "_" + (String) json.get("Genre") + "_" + (String) json.get("Score") + "\n"); contentReviews.write(Integer.toString(i) + " " + (String) json.get("Review")); i++; contentReviews.close(); } } br.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(System.out); } catch (IOException | ParseException ex) { ex.printStackTrace(System.out); } } } datosReviews.close(); }
From source file:com.yahoo.storm.yarn.TestConfig.java
synchronized File createYarnSiteConfig(Configuration yarn_conf) throws IOException { yarn_site_xml = new File("./target/conf/yarn-site.xml"); yarn_site_xml.getParentFile().mkdirs(); FileWriter writer = new FileWriter(yarn_site_xml); yarn_conf.writeXml(writer);// w w w .j a va 2 s .com writer.flush(); writer.close(); return yarn_site_xml; }
From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.FileUtilityTest.java
@Before public void setup() throws IOException { LOGGER.debug("TEMP_DIR = " + TEMP_DIR); File sampleDirectory = new File(TEMP_DIR + "/config"); LOGGER.debug("Temp dir/config created: " + sampleDirectory.mkdir()); File sampleFile1 = new File(sampleDirectory.getAbsolutePath() + "/tempfile1.tmp"); sampleFile1.createNewFile();/*www. jav a2 s . c o m*/ LOGGER.debug("SampleFile1 - " + sampleFile1.getAbsolutePath() + " - created: " + sampleFile1.isFile()); FileWriter fileWriter = new FileWriter(sampleFile1); fileWriter.append(FILE1_TEXT); fileWriter.close(); File sampleFile2 = new File(sampleDirectory.getAbsolutePath() + "/tempfile2.tmp"); sampleFile2.createNewFile(); LOGGER.debug("SampleFile2 - " + sampleFile2.getAbsolutePath() + " - created: " + sampleFile1.isFile()); fileWriter = new FileWriter(sampleFile2); fileWriter.append(FILE2_TEXT); fileWriter.close(); }