List of usage examples for java.io FileWriter flush
public void flush() throws IOException
From source file:com.mycompany.cafieldwaae.WAAEexecutejil.java
private void createOutputLocationFile(String outputLocation, String content, Boolean overwriteOutput) throws ActionException { File outputDirs = new File(outputLocation); if (!outputDirs.exists()) { try {// w w w . ja va 2 s . co m outputDirs.mkdirs(); } catch (SecurityException se) { log.error("Caught security exception while creating output location: " + outputLocation); throw new ActionException("Security exception while creating output location: " + se.getMessage(), se); } } String fileName = outputLocation + File.separator + SCRIPT_OUTPUT; try { FileWriter fw = new FileWriter(fileName, !overwriteOutput); fw.write(content); fw.flush(); fw.close(); } catch (IOException e) { log.error("Caught IO exception during writing to file"); throw new ActionException("IO exception during writing to file: " + e.getMessage(), e); } }
From source file:org.ala.spatial.web.services.SitesBySpeciesWSControllerTabulated.java
@RequestMapping(value = { "sxs/delete", "sxs/sxs/delete" }, method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView sxsDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException { String url = req.getParameter("u"); try {/* ww w . j a va2s . c o m*/ String pth = AlaspatialProperties.getAnalysisWorkingDir() + File.separator + "sxs" + File.separator; initListProperties(); Properties p = new Properties(); p.load(new FileReader(pth + "list.properties")); for (Entry<Object, Object> entry : p.entrySet()) { if (((String) entry.getValue()).equals(url)) { FileWriter fw = new FileWriter(pth + ((String) entry.getKey())); fw.write("-1"); fw.flush(); fw.close(); } } } catch (Exception e) { e.printStackTrace(); } return new ModelAndView("redirect:" + AlaspatialProperties.getAlaspatialUrl() + "/sxs"); }
From source file:dumptspacket.Main.java
public void start(String[] args) throws org.apache.commons.cli.ParseException { final String fileName; final Long limit; final Set<Integer> pids; System.out.println("args : " + dumpArgs(args)); final Option fileNameOption = Option.builder("f").required().longOpt("filename").desc("ts??") .hasArg().type(String.class).build(); final Option limitOption = Option.builder("l").required(false).longOpt("limit") .desc("??(???????EOF??)").hasArg() .type(Long.class).build(); final Option pidsOption = Option.builder("p").required().longOpt("pids") .desc("pid(?16?)").type(String.class).hasArgs().build(); Options opts = new Options(); opts.addOption(fileNameOption);/*w ww . j a v a 2 s . c om*/ opts.addOption(limitOption); opts.addOption(pidsOption); CommandLineParser parser = new DefaultParser(); CommandLine cl; HelpFormatter help = new HelpFormatter(); try { // parse options cl = parser.parse(opts, args); // handle interface option. fileName = cl.getOptionValue(fileNameOption.getOpt()); if (fileName == null) { throw new ParseException("????????"); } // handlet destination option. Long xl = null; try { xl = Long.parseUnsignedLong(cl.getOptionValue(limitOption.getOpt())); } catch (NumberFormatException e) { xl = null; } finally { limit = xl; } Set<Integer> x = new HashSet<>(); List<String> ls = new ArrayList<>(); ls.addAll(Arrays.asList(cl.getOptionValues(pidsOption.getOpt()))); for (String s : ls) { try { x.add(Integer.parseUnsignedInt(s, 16)); } catch (NumberFormatException e) { throw new ParseException(e.getMessage()); } } pids = Collections.unmodifiableSet(x); System.out.println("Starting application..."); System.out.println("filename : " + fileName); System.out.println("limit : " + limit); System.out.println("pids : " + dumpSet(pids)); // your code TsReader reader; if (limit == null) { reader = new TsReader(new File(fileName), pids); } else { reader = new TsReader(new File(fileName), pids, limit); } Map<Integer, List<TsPacketParcel>> ret = reader.getPackets(); try { for (Integer pid : ret.keySet()) { FileWriter writer = new FileWriter(fileName + "_" + Integer.toHexString(pid) + ".txt"); for (TsPacketParcel par : ret.get(pid)) { String text = Hex.encodeHexString(par.getPacket().getData()); writer.write(text + "\n"); } writer.flush(); writer.close(); } } catch (IOException ex) { LOG.fatal("", ex); } } catch (ParseException e) { // print usage. help.printHelp("My Java Application", opts); throw e; } catch (FileNotFoundException ex) { LOG.fatal("", ex); } }
From source file:com.consol.citrus.admin.service.spring.SpringBeanServiceTest.java
/** * Creates a temporary file in operating system and writes template content to file. * @param templateName/*from w ww . j a v a 2 s .co m*/ * @return */ private File createTempContextFile(String templateName) throws IOException { FileWriter writer = null; File tempFile; try { tempFile = File.createTempFile(templateName, ".xml"); writer = new FileWriter(tempFile); writer.write( FileUtils.readToString(new ClassPathResource(templateName + ".xml", SpringBeanService.class))); } finally { if (writer != null) { writer.flush(); writer.close(); } } return tempFile; }
From source file:org.ala.spatial.web.services.SitesBySpeciesWSControllerTabulated.java
public void run() throws IOException { synchronized (lockProperties) { //get all incomplete runs String pth = AlaspatialProperties.getAnalysisWorkingDir() + File.separator + "sxs" + File.separator; Properties p = new Properties(); p.load(new FileReader(pth + "list.properties")); ArrayList<SxS> list = new ArrayList<SxS>(); for (Entry entry : p.entrySet()) { if (!new File(pth + entry.getKey()).exists()) { list.add(new SxS((String) entry.getValue(), (String) entry.getKey(), "")); }//from w ww . ja v a2 s . c om } for (SxS sxs : list) { String url = AlaspatialProperties.getAlaspatialUrl() + "ws/sitesbyspeciestabulated?" + sxs.getValue() + "&bs=" + AlaspatialProperties.getBiocacheWsURL(); try { //start GetMethod get = new GetMethod(url); HttpClient client = new HttpClient(); client.executeMethod(get); if (get.getStatusCode() == 200) { String id = get.getResponseBodyAsString(); long lid = Long.parseLong(id); //test analysis id FileWriter fw = new FileWriter(pth + sxs.getAnalysisId()); fw.write(id); fw.flush(); fw.close(); } else { System.out.println("sxs failed for: " + url); System.out.println("response code: " + get.getStatusCode()); FileWriter fw = new FileWriter(pth + sxs.getAnalysisId()); fw.write("0"); fw.flush(); fw.close(); } } catch (Exception e) { System.out.println("sxs failed for: " + url); e.printStackTrace(); FileWriter fw = new FileWriter(pth + sxs.getAnalysisId()); fw.write("0"); fw.flush(); fw.close(); } } } }
From source file:com.exlibris.dps.delivery.vpp.mirador.MiradorViewerPreProcessor.java
public void writeManifest(JSONObject manifest, String pid) { try {//from ww w . j av a 2 s. c om // Writing to a file File file = new File("//operational_shared//mirador//" + pid + "manifest.json"); file.createNewFile(); FileWriter fileWriter = new FileWriter(file); fileWriter.write(manifest.toString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.csw.expertfinder.mediawiki.api.MediaWikiAPI.java
public static void eraseRedirects(MediaWikiAPI w) { try {/*w w w. j a va2 s .c o m*/ BufferedReader in = new BufferedReader( new FileReader("Z:\\csw\\Dipomarbeit\\Evaluierung\\Alle Artikel.txt")); FileWriter out = new FileWriter("Z:\\csw\\Dipomarbeit\\Evaluierung\\Alle Artikel ohne Redirects.txt"); String articleName; while ((articleName = in.readLine()) != null) { String actualName = w.getActualArticleName(articleName); if (articleName.equals(actualName)) { out.write(articleName + "\n"); } // else { // System.out.println("Omitting: " + articleName + " -> " + actualName); // } } out.flush(); out.close(); in.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MediaWikiAPIException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.fcrepo.importexport.integration.ExecutableJarIT.java
@Test public void testConfigFileExport() throws Exception { // Create a repository resource final FcrepoResponse response = create(url); assertEquals(SC_CREATED, response.getStatusCode()); assertEquals(url, response.getLocation()); // Create test config file final File configFile = File.createTempFile("config-test", ".txt"); final FileWriter writer = new FileWriter(configFile); writer.append("-d\n"); writer.append(TARGET_DIR);/* w ww. ja v a 2 s . c o m*/ writer.append("\n"); writer.append("-m\n"); writer.append("export\n"); writer.append("-r\n"); writer.append(url.toString()); writer.append("\n"); writer.flush(); // Run an export process final Process process = startJarProcess("-c", configFile.getAbsolutePath(), "-u", "fedoraAdmin:password"); // Verify assertTrue("Process did not exit before timeout!", process.waitFor(TIMEOUT_SECONDS, TimeUnit.SECONDS)); assertEquals("Did not exit with success status!", 0, process.exitValue()); assertTrue(new File(TARGET_DIR, TransferProcess.encodePath(url.getPath() + ArgParser.DEFAULT_RDF_EXT)) .exists()); assertTrue(new File(System.getProperty("java.io.tmpdir"), ArgParser.CONFIG_FILE_NAME).exists()); }
From source file:hudson.plugins.dimensionsscm.DimensionsChangeLogWriter.java
public boolean writeLog(List<DimensionsChangeSet> changeSets, File changelogFile) throws IOException { boolean bRet = false; boolean appendFile = false; FileWriter logFile = null; if (changelogFile.exists()) { if (changelogFile.length() > 0) { appendFile = true;/* w w w. j a v a 2 s. co m*/ } } try { logFile = new FileWriter(changelogFile, appendFile); write(changeSets, logFile, appendFile); logFile.flush(); bRet = true; } catch (Exception e) { e.printStackTrace(); throw new IOException("Unable to write change log - " + e.getMessage()); } finally { logFile.close(); } return bRet; }
From source file:com.ca.servicenow.AttachFile.java
private void createOutputLocationFile(String outputLocation, String content) throws ActionException { File outputDirs = new File(outputLocation); if (!outputDirs.exists()) { try {/*from www. ja v a2s. c o m*/ outputDirs.mkdirs(); } catch (SecurityException se) { log.error("Caught security exception while creating output location: " + outputLocation); throw new ActionException("Security exception while creating output location: " + se.getMessage(), se); } } String fileName = outputLocation + File.separator + WEBSERVICE_OUTPUT; try { FileWriter fw = new FileWriter(fileName); fw.write(content); fw.flush(); fw.close(); } catch (IOException e) { log.error("Caught IO exception during writing to file"); throw new ActionException("IO exception during writing to file: " + e.getMessage(), e); } }