List of usage examples for java.io Writer close
public abstract void close() throws IOException;
From source file:ark.data.annotation.DataSet.java
public boolean serialize(Writer writer) throws IOException { for (D datum : this) { JSONObject json = this.datumTools.datumToJSON(datum); writer.write(json.toString());/*from ww w . ja v a2s . co m*/ writer.write("\n"); } writer.close(); return true; }
From source file:MapTranslater.java
public void endDocument() throws SAXException { try {/*from w ww. ja v a2 s . c om*/ nl(); out.flush(); } catch (IOException e) { throw new SAXException("I/O error", e); } // Stats handling: if (statFile != null) { try { Writer wr = new OutputStreamWriter(new FileOutputStream(statFile), "UTF-8"); for (String item : stats.keySet()) { wr.write(item); wr.write('\t'); wr.write(stats.get(item).toString()); wr.write('\n'); } wr.close(); } catch (IOException e) { throw new SAXException("Stat writing error", e); } } }
From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java
@Before public void setUp() throws Exception { // overwrite TEST_FILENAME with content for our needs final Writer writer = new BufferedWriter(new FileWriter(new File(testDir, TEST_FILENAME))); for (int i = 0; i < TEST_FILE_A_CHARS_NUMBER; i++) { writer.write("a"); }/* w ww.java 2 s.co m*/ for (int i = 0; i < TEST_FILE_B_CHARS_NUMBER; i++) { writer.write("b"); } writer.close(); // start FileSystemServer with proper settings CentralPAPropertyRepository.PA_VFSPROVIDER_SERVER_STREAM_AUTOCLOSE_CHECKING_INTERVAL_MILLIS .setValue(CHECKING_TIME); CentralPAPropertyRepository.PA_VFSPROVIDER_SERVER_STREAM_OPEN_MAXIMUM_PERIOD_MILLIS .setValue(AUTOCLOSE_TIME); serverDeployer = new FileSystemServerDeployer(testDir.getAbsolutePath(), true); // set up VFS manager with ProActiveProvider vfsManager = VFSFactory.createDefaultFileSystemManager(); }
From source file:adapters.XYChartAdapter.java
/** * Transforms the chart to <SPAN CLASS="logo,LaTeX">L<SUP><SMALL>A</SMALL></SUP>T<SMALL>E</SMALL>X</SPAN> form and writes it in file <TT>fileName</TT>. * The chart's width and height (in centimeters) are <TT>width</TT> and <TT>height</TT>. * *///w w w.jav a 2s .c o m public void toLatexFile(String fileName, double width, double height) { String output = toLatex(width, height); Writer file = null; try { file = new FileWriter(fileName); file.write(output); file.close(); } catch (IOException e) { System.err.println(" toLatexFile: cannot write to " + fileName); e.printStackTrace(); try { if (file != null) file.close(); } catch (IOException ioe) { } } }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLWriter.java
public void write(String filename) { if (!filename.endsWith(".xml")) filename += ".xml"; log.info("write vrp: " + filename); XMLConf xmlConfig = new XMLConf(); xmlConfig.setFileName(filename);/*www. java 2 s. com*/ xmlConfig.setRootElementName("problem"); xmlConfig.setAttributeSplittingDisabled(true); xmlConfig.setDelimiterParsingDisabled(true); writeProblemType(xmlConfig); writeVehiclesAndTheirTypes(xmlConfig); //might be sorted? List<Job> jobs = new ArrayList<Job>(); jobs.addAll(vrp.getJobs().values()); for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { jobs.addAll(r.getTourActivities().getJobs()); } writeServices(xmlConfig, jobs); writeShipments(xmlConfig, jobs); writeInitialRoutes(xmlConfig); writeSolutions(xmlConfig); OutputFormat format = new OutputFormat(); format.setIndenting(true); format.setIndent(5); try { Document document = xmlConfig.createDoc(); Element element = document.getDocumentElement(); element.setAttribute("xmlns", "http://www.w3schools.com"); element.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); element.setAttribute("xsi:schemaLocation", "http://www.w3schools.com vrp_xml_schema.xsd"); } catch (ConfigurationException e) { throw new RuntimeException(e); } try { Writer out = new FileWriter(filename); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(xmlConfig.getDocument()); out.close(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:example.TestLineRecordReader.java
/** * Writes the input test file// w w w . j av a2 s.c o m * * @param conf * @return Path of the file created * @throws IOException */ private Path createInputFile(Configuration conf, String data) throws IOException { FileSystem localFs = FileSystem.getLocal(conf); Path file = new Path(inputDir, "test.txt"); Writer writer = new OutputStreamWriter(localFs.create(file)); try { writer.write(data); } finally { writer.close(); } return file; }
From source file:com.cdd.bao.importer.KeywordMapping.java
public void save() throws IOException { JSONObject json = new JSONObject(); JSONArray listID = new JSONArray(), listText = new JSONArray(), listProp = new JSONArray(); JSONArray listVal = new JSONArray(), listLit = new JSONArray(), listRef = new JSONArray(), listAsrt = new JSONArray(); for (Identifier id : identifiers) { JSONObject obj = new JSONObject(); obj.put("regex", id.regex); obj.put("prefix", id.prefix); listID.put(obj);// ww w . ja va 2s . co m } for (TextBlock txt : textBlocks) { JSONObject obj = new JSONObject(); obj.put("regex", txt.regex); obj.put("title", txt.title); listText.put(obj); } for (Property prop : properties) { JSONObject obj = new JSONObject(); obj.put("regex", prop.regex); obj.put("propURI", prop.propURI); obj.put("groupNest", prop.groupNest); listProp.put(obj); } for (Value val : values) { JSONObject obj = new JSONObject(); obj.put("regex", val.regex); obj.put("valueRegex", val.valueRegex); obj.put("valueURI", val.valueURI); obj.put("propURI", val.propURI); obj.put("groupNest", val.groupNest); listVal.put(obj); } for (Literal lit : literals) { JSONObject obj = new JSONObject(); obj.put("regex", lit.regex); obj.put("valueRegex", lit.valueRegex); obj.put("propURI", lit.propURI); obj.put("groupNest", lit.groupNest); listLit.put(obj); } for (Reference ref : references) { JSONObject obj = new JSONObject(); obj.put("regex", ref.regex); obj.put("valueRegex", ref.valueRegex); obj.put("prefix", ref.prefix); obj.put("propURI", ref.propURI); obj.put("groupNest", ref.groupNest); listRef.put(obj); } for (Assertion asrt : assertions) { JSONObject obj = new JSONObject(); obj.put("propURI", asrt.propURI); obj.put("groupNest", asrt.groupNest); obj.put("valueURI", asrt.valueURI); listAsrt.put(obj); } json.put("identifiers", listID); json.put("textBlocks", listText); json.put("properties", listProp); json.put("values", listVal); json.put("literals", listLit); json.put("references", listRef); json.put("assertions", listAsrt); Writer wtr = new FileWriter(file); wtr.write(json.toString(2)); wtr.close(); }
From source file:com.mousefeed.eclipse.preferences.PreferenceAccessor.java
/** * Saves settings loaded by {@link #loadActionsOnWrongInvocationMode()}. *///w w w. j a v a 2s . c o m private void saveActionsOnWrongInvocationMode() { final XMLMemento memento = createActionsOnWrongInvocationModeMemento(); Writer writer = null; try { writer = new FileWriter(getActionsWrongInvocationModeFile()); memento.save(writer); } catch (final IOException e) { throw new RuntimeException(e); } finally { try { if (writer != null) { writer.close(); } } catch (final IOException e) { throw new RuntimeException(e); } } }
From source file:com.sun.faban.harness.webclient.ResultAction.java
/** * Obtains the tags list for each profile. * @param req//from w w w.j a v a 2 s. c o m * @param resp * @throws java.io.IOException */ public void profileTagList(HttpServletRequest req, HttpServletResponse resp) throws IOException { String profile = req.getParameter("profileselected"); File tagsFile = new File(Config.PROFILES_DIR + profile + "/tags"); String tagsForProfile = ""; if (tagsFile.exists() && tagsFile.length() > 0) { tagsForProfile = FileHelper.readContentFromFile(tagsFile).trim(); } Writer w = resp.getWriter(); w.write(tagsForProfile); w.flush(); w.close(); }
From source file:org.psidnell.omnifocus.Main.java
private void run() throws Exception { Writer out; if (outputFile != null) { out = new BufferedWriter(new FileWriter(outputFile)); } else {// w ww . j a v a 2s . c om out = new BufferedWriter(IOUtils.systemOutWriter()); } if (format != null) { ofexport.setFormat(format.toLowerCase()); } else if (outputFile != null && outputFile.contains(".")) { int dot = outputFile.indexOf('.'); ofexport.setFormat(outputFile.substring(dot + 1).toLowerCase()); } ofexport.process(); ofexport.write(out); out.flush(); out.close(); if (open) { String[] cmdargs = { "open", outputFile }; Process p = Runtime.getRuntime().exec(cmdargs); try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) { org.apache.commons.io.IOUtils.copy(input, System.out); } } }