List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:com.provenance.cloudprovenance.policyhandler.ws.support.PolicyRequestProcessor.java
private void storeRequest(String requestId, String requestContent, HttpServletRequest request) throws IOException { File requestFile = new File( request.getRealPath(cProvlRequestDirectoryPath) + "/request" + requestId + "-cprovl.xml"); logger.info("File URI: " + requestFile.getAbsolutePath()); requestFile.createNewFile();/*w w w . j av a 2 s .com*/ FileWriter fWritter = new FileWriter(requestFile); fWritter.write(requestContent); fWritter.close(); }
From source file:com.thoughtworks.go.domain.builder.FetchPluggableArtifactBuilderTest.java
@Test public void shouldCallArtifactExtensionWithMetadata() throws IOException { final FetchPluggableArtifactBuilder builder = new FetchPluggableArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "", jobIdentifier, artifactStore, fetchPluggableArtifactTask.getConfiguration(), fetchPluggableArtifactTask.getArtifactId(), sourceOnServer, metadataDest, checksumFileHandler); final Map<String, Object> metadata = Collections.singletonMap("Version", "10.12.0"); final FileWriter fileWriter = new FileWriter(metadataDest); fileWriter.write(new Gson().toJson(metadata)); fileWriter.close(); builder.build(publisher, new EnvironmentVariableContext(), null, artifactExtension, registry, "utf-8"); verify(artifactExtension).fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), eq(fetchPluggableArtifactTask.getConfiguration()), any(), eq(metadataDest.getParent())); }
From source file:com.hp.alm.ali.idea.services.AttachmentServiceTest.java
private File createFile() throws IOException { File tempFile = File.createTempFile("AttachmentServiceTest", null); tempFile.deleteOnExit();// w w w . ja va2 s. c om FileWriter fw = new FileWriter(tempFile); IOUtils.copy(new StringReader("content"), fw); fw.close(); return tempFile; }
From source file:es.csic.iiia.planes.cli.Cli.java
/** * Parse the provided list of arguments according to the program's options. * /*from w ww . ja v a 2 s . co m*/ * @param in_args * list of input arguments. * @return a configuration object set according to the input options. */ private static Configuration parseOptions(String[] in_args) { CommandLineParser parser = new PosixParser(); CommandLine line = null; Properties settings = loadDefaultSettings(); try { line = parser.parse(options, in_args); } catch (ParseException ex) { Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex); showHelp(); } if (line.hasOption('h')) { showHelp(); } if (line.hasOption('d')) { dumpSettings(); } if (line.hasOption('s')) { String fname = line.getOptionValue('s'); try { settings.load(new FileReader(fname)); } catch (IOException ex) { throw new IllegalArgumentException("Unable to load the settings file \"" + fname + "\""); } } // Apply overrides settings.setProperty("gui", String.valueOf(line.hasOption('g'))); settings.setProperty("quiet", String.valueOf(line.hasOption('q'))); Properties overrides = line.getOptionProperties("o"); settings.putAll(overrides); String[] args = line.getArgs(); if (args.length < 1) { showHelp(); } settings.setProperty("problem", args[0]); Configuration c = new Configuration(settings); System.out.println(c.toString()); /** * Modified by Guillermo B. Print settings to a result file, titled * "results.txt" */ try { FileWriter fw = new FileWriter("results.txt", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw); String[] results = c.toString().split("\n"); // out.println(results[8]); for (String s : results) { out.println(s); } // out.println(results[2]); // out.println(results[8]); out.close(); } catch (IOException e) { } /** * Modified by Ebtesam Save settings to a .csv file, titled * "resultsCSV.csv" */ try { FileWriter writer = new FileWriter("resultsCSV.csv", true); FileReader reader = new FileReader("resultsCSV.csv"); String header = "SAR Strategy,# of Searcher UAVs,# of Survivors," + "# of Survivors rescued,Min.Time needed to rescue Survivors,Mean. Time needed to rescue Survivors,Max. Time needed to rescue Survivors," + "# of Survivors found,Min. Time needed to find Survivors,Mean Time needed to find Survivors,Max. Time needed to find Survivors," + "Running Time of Simulation\n"; if (reader.read() == -1) { writer.append(header); writer.append("\n"); } reader.close(); String[] results = c.toString().split("\n"); writer.append(results[2].substring(10)); writer.append(","); writer.append(results[20].substring(11)); writer.append(","); writer.append(results[30].substring(18)); writer.write(","); writer.close(); } catch (IOException e) { } if (line.hasOption('t')) { System.exit(0); } return c; }
From source file:forumbox.PostingnewpostServlet.java
public void filewrite(String url, String username, String title, String description, HttpServletResponse response, String id) throws IOException { count++;/*from w w w .jav a 2 s . co m*/ /* BufferedWriter out ; out = new BufferedWriter(new FileWriter(url,true)); out.write(count+"/"+array[0]+"/"+array[1]+"/"+array[2]+";"); out.close(); }catch (Exception e) { System.out.println("Error: " + e.getMessage()); } */ JSONObject post = new JSONObject(); JSONArray comments = new JSONArray(); JSONArray toapprove = new JSONArray(); JSONParser parser = new JSONParser(); JSONObject list = null; post.put("title", title); post.put("description", description); post.put("id", id); post.put("username", username); // post.put("comments",comments); // post.put("toapprove",toapprove); try { Object obj = parser.parse(new FileReader(url + "list.json")); list = (JSONObject) obj; JSONArray msg = (JSONArray) list.get("list"); msg.add(id); list.remove("list"); list.put("list", msg); } catch (Exception e) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Adding new ID is unsuccessful"); out.println(e); out.println("......................"); } try { File file = new File(url + id + ".json"); file.createNewFile(); BufferedWriter out; out = new BufferedWriter(new FileWriter(file)); out.write(post.toJSONString()); out.close(); File fileList = new File(url + "list.json"); // fileList.createNewFile(); // BufferedWriter outin ; // outin = new BufferedWriter(new FileWriter(fileList)); // outin.write(post.toJSONString()); FileWriter listwrite = new FileWriter(fileList); listwrite.write(list.toJSONString()); listwrite.flush(); listwrite.close(); //outin.close(); } catch (IOException e) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("adding new post is unsuccessful"); out.println(e); out.println("......................"); } }
From source file:presenter.MainPresenter.java
@Override public void saveEmissionsequenceToFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); if (fc.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try {//from w ww.j ava 2s . c o m FileWriter fw = new FileWriter(file); fw.write(this.emissionsequenceModel.toString()); fw.flush(); fw.close(); this.displayStatus("File was written successfully!"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:com.thoughtworks.go.domain.builder.FetchPluggableArtifactBuilderTest.java
@Test public void shouldRegisterAndDeRegisterArtifactRequestProcessBeforeAndAfterPublishingPluggableArtifact() throws IOException { final FetchPluggableArtifactBuilder builder = new FetchPluggableArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "", jobIdentifier, artifactStore, fetchPluggableArtifactTask.getConfiguration(), fetchPluggableArtifactTask.getArtifactId(), sourceOnServer, metadataDest, checksumFileHandler); final Map<String, Object> metadata = Collections.singletonMap("Version", "10.12.0"); final FileWriter fileWriter = new FileWriter(metadataDest); fileWriter.write(new Gson().toJson(metadata)); fileWriter.close(); builder.build(publisher, new EnvironmentVariableContext(), null, artifactExtension, registry, "utf-8"); InOrder inOrder = inOrder(registry, artifactExtension); inOrder.verify(registry, times(1)).registerProcessorFor(eq(CONSOLE_LOG.requestName()), ArgumentMatchers.any(ArtifactRequestProcessor.class)); inOrder.verify(artifactExtension).fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), eq(fetchPluggableArtifactTask.getConfiguration()), any(), eq(metadataDest.getParent())); inOrder.verify(registry, times(1)).removeProcessorFor(CONSOLE_LOG.requestName()); }
From source file:lineage.LineageEngine.java
private static void writeTreesToTxtFile(PHYNetwork net, ArrayList<PHYTree> trees, ArrayList<String> sampleNames, Args args) {//from w ww.j a v a 2 s . c o m String treeFileName = args.outputFileName; try { FileWriter fw = new FileWriter(treeFileName); fw.write("Nodes:\n" + net.getNodesWithMembersAsString() + "\n"); for (int i = 0; i < args.numSave; i++) { if (trees.size() > i) { fw.write("****Tree " + i + "****\n"); String edges = trees.get(i).toString(); fw.write(edges); fw.write("Error score: " + trees.get(i).getErrorScore() + "\n\n"); fw.write("Sample decomposition: \n"); String lineage = ""; for (int j = 0; j < sampleNames.size(); j++) { lineage += trees.get(i).getLineage(j, sampleNames.get(j)); lineage += "\n"; } fw.write(lineage); fw.write("\n"); } } fw.write("SNV info:\n" + net.getNodeMembersOnlyAsString() + "\n"); fw.close(); } catch (IOException e) { e.printStackTrace(); System.err.println("Failed to write to the file: " + treeFileName); System.exit(-1); } }
From source file:com.linkedin.pinot.core.data.readers.ThriftRecordReaderTest.java
@BeforeClass public void setUp() throws IOException, TException { ThriftSampleData t1 = new ThriftSampleData(); t1.setActive(true);/* w w w . j av a 2s . co m*/ t1.setCreated_at(1515541280L); t1.setId(1); t1.setName("name1"); List<Short> t1Groups = new ArrayList<>(2); t1Groups.add((short) 1); t1Groups.add((short) 4); t1.setGroups(t1Groups); Map<String, Long> mapValues = new HashMap<>(); mapValues.put("name1", 1L); t1.setMap_values(mapValues); Set<String> namesSet = new HashSet<>(); namesSet.add("name1"); t1.setSet_values(namesSet); ThriftSampleData t2 = new ThriftSampleData(); t2.setActive(false); t2.setCreated_at(1515541290L); t2.setId(2); t2.setName("name2"); List<Short> t2Groups = new ArrayList<>(2); t2Groups.add((short) 2); t2Groups.add((short) 3); t2.setGroups(t2Groups); List<ThriftSampleData> lists = new ArrayList<>(2); lists.add(t1); lists.add(t2); TSerializer binarySerializer = new TSerializer(new TBinaryProtocol.Factory()); _tempFile = getSampleDataPath(); FileWriter writer = new FileWriter(_tempFile); for (ThriftSampleData d : lists) { IOUtils.write(binarySerializer.serialize(d), writer); } writer.close(); }
From source file:com.ut.healthelink.service.CCDtoTxt.java
public String TranslateCCDtoTxt(String fileLocation, String ccdFileName, 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 CCDObj = constructor.newInstance(); Method myMethod = cls.getMethod("CCDtoTxt", new Class[] { File.class }); /* Get the uploaded CCD File */ fileLocation = fileLocation.replace("/Applications/bowlink/", "").replace("/home/bowlink/", "") .replace("/bowlink/", ""); dir.setDirByName(fileLocation);/*from w w w.ja v a 2 s . co m*/ File ccdFile = new File(dir.getDir() + ccdFileName + ".xml"); /* Create the txt file that will hold the CCD fields */ String newfileName = new StringBuilder() .append(ccdFile.getName().substring(0, ccdFile.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 (Exception e) { e.printStackTrace(); } } else { newFile.createNewFile(); newfileName = newFile.getName(); } FileWriter fw = new FileWriter(newFile, true); /* END */ String fileRecords = (String) myMethod.invoke(CCDObj, new Object[] { ccdFile }); fw.write(fileRecords); fw.close(); return newfileName; }