List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:com.comcast.cdn.traffic_control.traffic_router.core.dns.ZoneManager.java
private static void writeZone(final Zone zone) throws IOException { synchronized (LOGGER) { if (!zoneDirectory.exists() && !zoneDirectory.mkdirs()) { LOGGER.error(zoneDirectory.getAbsolutePath() + " directory does not exist and cannot be created!"); }//ww w .ja v a 2 s . c om final File zoneFile = new File(getZoneDirectory(), zone.getOrigin().toString()); final FileWriter w = new FileWriter(zoneFile); LOGGER.info("writing: " + zoneFile.getAbsolutePath()); IOUtils.write(zone.toMasterFile(), w); w.flush(); w.close(); } }
From source file:org.xsocket.connection.SpringTest.java
@Test public void testSimple() throws Exception { File file = QAUtil.createTempfile(); FileWriter fw = new FileWriter(file); fw.write(SPRING_XML);/*from www .java 2s . co m*/ fw.close(); BeanFactory beanFactory = new XmlBeanFactory(new FileSystemResource(file)); IServer server = (IServer) beanFactory.getBean("server"); Assert.assertTrue(server.isOpen()); assert (server.isOpen() == true); IBlockingConnection connection = new BlockingConnection("localhost", server.getLocalPort()); connection.setAutoflush(true); String request = "3453543535"; connection.write(request + EchoHandler.DELIMITER); String response = connection.readStringByDelimiter(EchoHandler.DELIMITER, Integer.MAX_VALUE); connection.close(); Assert.assertTrue(request.equals(response)); file.delete(); server.close(); }
From source file:com.karki.spring.dao.impl.FacilitatorDaoImpl.java
@Override public void exportData(String filename, String content) throws IOException, ClassNotFoundException, SQLException { FileWriter fileWriter = new FileWriter(new File(filename)); fileWriter.write(content);// w ww . j av a2 s .c o m fileWriter.close(); }
From source file:jetbrains.exodus.util.CompressBackupUtilTest.java
@Test public void testFileArchived() throws Exception { File src = new File(randName + ".txt"); FileWriter fw = new FileWriter(src); fw.write("12345"); fw.close(); CompressBackupUtil.tar(src, dest);/*w w w. ja v a 2 s . c om*/ Assert.assertTrue("No destination archive created", dest.exists()); TarArchiveInputStream tai = new TarArchiveInputStream( new GZIPInputStream(new BufferedInputStream(new FileInputStream(dest)))); ArchiveEntry entry = tai.getNextEntry(); Assert.assertNotNull("No entry found in destination archive", entry); Assert.assertEquals("Entry has wrong size", 5, entry.getSize()); }
From source file:de.andrena.tools.macker.plugin.CommandLineFileTest.java
public void testInvokeEmptyFile() throws Exception { FileWriter out = new FileWriter(TEST_FILE); out.flush();//from w w w .j a v a 2s . c o m out.close(); CommandLineFile.main(new String[] { SetArgs.class.getName(), TEST_FILE.toString() }); assertNotNull(SetArgs.getLastArgs()); assertEquals(0, SetArgs.getLastArgs().length); }
From source file:org.powertac.producer.fossil.SteamPlantTest.java
@Test public void dataGenerateXML() throws IOException { Competition.newInstance("Fossil Plant test"); SteamPlant plant = new SteamPlant(10000, 5000, -500000); XStream xstream = new XStream(); xstream.autodetectAnnotations(true); new File("data/").mkdir(); FileWriter fw = new FileWriter("data/steam-plant.xml"); xstream.toXML(plant, fw);// www . j a va2 s. c om fw.close(); }
From source file:com.amazonaws.auth.profile.ProfilesConfigFileWriter.java
/** * Write all the credential profiles to a file. Note that this method will * clobber the existing content in the destination file if it's in the * overwrite mode. Use {@link #modifyOrInsertProfiles(File, Profile...)} * instead, if you want to perform in-place modification on your existing * credentials file.//w ww. j a v a 2s . c o m * * @param destination * The destination file where the credentials will be written to. * @param overwrite * If true, this method If false, this method will throw * exception if the file already exists. * @param profiles * All the credential profiles to be written. */ public static void dumpToFile(File destination, boolean overwrite, Profile... profiles) { if (destination.exists() && !overwrite) { throw new AmazonClientException("The destination file already exists. " + "Set overwrite=true if you want to clobber the existing " + "content and completely re-write the file."); } FileWriter writer; try { writer = new FileWriter(destination, false); // append=false } catch (IOException ioe) { throw new AmazonClientException("Unable to open the destination file.", ioe); } try { final Map<String, Profile> modifications = new LinkedHashMap<String, Profile>(); for (Profile profile : profiles) { modifications.put(profile.getProfileName(), profile); } ProfilesConfigFileWriterHelper writerHelper = new ProfilesConfigFileWriterHelper(writer, modifications); writerHelper.writeWithoutExistingContent(); } finally { try { writer.close(); } catch (IOException ioe) { } } }
From source file:facebook4j.internal.http.MockHttpClientWrapper.java
private void registerMockJSON(String json) throws IOException { String baseDir = System.getProperty("user.dir"); if (!baseDir.endsWith("/facebook4j-core")) { baseDir += "/facebook4j-core"; }/*w w w . j a v a 2s . c o m*/ File file = new File(baseDir + "/src/test/resources/" + mockJSONResourceName); new File(file.getParent()).mkdirs(); FileWriter writer = new FileWriter(file); writer.write(json); writer.close(); }
From source file:com.linkedin.pinot.tools.admin.command.AbstractBaseAdminCommand.java
protected void savePID(String fileName) throws IOException { FileWriter pidFile = new FileWriter(fileName); pidFile.write(getPID());//from ww w . j a v a 2s.c o m pidFile.close(); }
From source file:de.bley.word.filewriter.WriterFile.java
/** * Ueberschreibt den Inhalt einer Textdatei. * * @param filepath Pfad der zulesenden Datei. * @param text String, welcher in die Datei geschrieben werden soll. * *//*from www.jav a 2 s . c o m*/ @Override public void overwriteFile(String filepath, String text) { try { FileWriter writer = new FileWriter(filepath, false); writer.write(text); writer.close(); } catch (IOException e) { e.printStackTrace(); } }