List of usage examples for java.io FileWriter flush
public void flush() throws IOException
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.LongKeyResourceTest.java
public void testSearch() throws Exception { try {// w ww. j av a 2s .c o m String url = baseURL + "/rest/LongKey/search;id=*"; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("LongKey_Search" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.LongPrimitiveKeyResourceTest.java
public void testSearch() throws Exception { try {//from ww w.j a v a2s. c om String url = baseURL + "/rest/LongPrimitiveKey/search;id=*"; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("LongPrimitiveKey_Search" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.NoIdKeyResourceTest.java
public void testSearch() throws Exception { try {/* w w w . j a va 2s. c o m*/ String url = baseURL + "/rest/NoIdKey/search;mykey=*"; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("NoIdKey_Search" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.StringKeyResourceTest.java
public void testSearch() throws Exception { try {// ww w . j a v a 2 s .com String url = baseURL + "/rest/StringKey/search;id=*"; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("StringKey_Search" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.StringPrimitiveKeyResourceTest.java
public void testSearch() throws Exception { try {//from w ww . j a v a2 s . com String url = baseURL + "/rest/StringPrimitiveKey/search;id=*"; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("StringPrimitiveKey_Search" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.gov.nih.nci.cacoresdk.domain.other.validationtype.AllValidationTypeResourceTest.java
public void testSearch() throws Exception { try {/* www . jav a2s. c o m*/ String url = baseURL + "/rest/AllValidationType/search;id=*"; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("AllValidationType_Search" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Interface.MainJFrame.java
private void btnJSONActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnJSONActionPerformed // TODO add your handling code here: JSONWriter jsonWriter = null;//w ww . ja v a2 s . c om JSONObject obj = new JSONObject(); try { obj.put("Name", txtFullName.getText().trim()); obj.put("ID", txtEmployeeID.getText().trim()); obj.put("Phone", txtPhoneNumber.getText().trim()); obj.put("Address", txtAddress.getText().trim()); obj.put("Title", txtEmployeeType.getText().trim()); obj.put("PayCategory", txtPayCategory.getText().trim()); obj.put("Salary", txtSalary.getText().trim()); obj.put("Hours", txtHours.getText().trim()); obj.put("Bonuses", txtBonuses.getText().trim()); obj.put("Total", txtTotal.getText().trim()); } catch (Exception e) { } // try-with-resources statement based on post comment below :) try { FileWriter file = new FileWriter("JSONoutput"); file.write(obj.toString()); file.flush(); file.close(); } catch (Exception e) { } }
From source file:helpers.Methods.java
/** * This method will store the remaining links to the LOGS/Links.csv *//* w w w .j a v a2 s.co m*/ public static void makeLinksLogs() { FileWriter out = null; try { File inputDirectory = new File(Variables.inputFile); File outputFile = new File(checkDirectory(inputDirectory.getParent()) + File.separator + "Links.csv"); if (outputFile.getParentFile() != null) { outputFile.getParentFile().mkdirs(); } out = new FileWriter(outputFile); String tmp = ""; tmp = Variables.inputFileOutputFileName + "," + Variables.inputFileLinksColumnName + "\r\n"; out.write(tmp); //CSV Header for (WebDocument doc : getRemainingProfileLinks()) { doc.resetCounter(); tmp = doc.getOutputName() + ","; String url = doc.getNextUrl(); while (url != null) { tmp += url + Variables.inputFileLinksSeparator; url = doc.getNextUrl(); } //remove last separator //TODO Check the sustring works fine or not. //Error occured when all threads finished their work. tmp = tmp.substring(0, tmp.lastIndexOf(Variables.inputFileLinksSeparator)); out.write(tmp + "\r\n"); out.flush(); } out.close(); } catch (IOException ex) { Variables.logger.Log(Methods.class, Variables.LogType.Error, "Error in saving remaining links. Details:\r\n" + ex.getMessage()); } }
From source file:bridge.toolkit.commands.SCOBuilder.java
/** * The unit of processing work to be performed for the SCOBuilder module. * // w w w . ja v a 2 s. co m * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context) */ @Override public boolean execute(Context ctx) { System.out.println("Executing SCOBuilder"); commonFiles = new ArrayList<String>(); //System.out.println("Executing SCOBuilder"); //System.out.flush(); if ((ctx.get(Keys.XML_SOURCE) != null) && (ctx.get(Keys.RESOURCE_PACKAGE) != null) && (ctx.get(Keys.SCPM_FILE) != null)) { //check to see if a cp_package directory exist yet if (ctx.get(Keys.CP_PACKAGE) == null) { ContentPackageCreator cpc = new ContentPackageCreator((String) ctx.get(Keys.RESOURCE_PACKAGE)); try { cpPackage = cpc.createPackage(); } catch (IOException e) { System.out.println(SCOBUILDER_FAILED); e.printStackTrace(); return PROCESSING_COMPLETE; } catch (JDOMException e) { System.out.println(SCOBUILDER_FAILED); e.printStackTrace(); return PROCESSING_COMPLETE; } ctx.put(Keys.CP_PACKAGE, cpPackage); } else { cpPackage = (File) ctx.get(Keys.CP_PACKAGE); } try { //copy necessary files over to CP folder copyViewerAppFiles(); //apply the SCORM CP XSLT StyleSheet to the data modules StylesheetApplier sa = new StylesheetApplier(); if (ctx.get(Keys.OUTPUT_TYPE) == "SCORMHTML") { sa.applyStylesheetToDMCs(cpPackage, CPHTMLSTYLESHEET); } else { sa.applyStylesheetToDMCs(cpPackage, CPSTYLESHEET); } //create list.js, add to CP dmp = new DMParser(); manifest = (Document) ctx.get(Keys.XML_SOURCE); File scpmFile = new File((String) ctx.get(Keys.SCPM_FILE)); scpm = dmp.getDoc(scpmFile); generateListFile(); //write urn map to cp app location Document urn_map = (Document) ctx.get(Keys.URN_MAP); File js = new File(cpPackage + File.separator + "resources/s1000d/app/urn_resource_map.xml"); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileWriter writer = new FileWriter(js); outputter.output(urn_map, writer); writer.flush(); writer.close(); //System.out.println("A " + js.getAbsolutePath()); commonFiles.add(js.getAbsolutePath()); //add as a common resource element generateCommonResource(); //build launchable htm files and add to manifest generateLaunchableFile(); } catch (JDOMException e) { System.out.println(SCOBUILDER_FAILED); e.printStackTrace(); return PROCESSING_COMPLETE; } catch (IOException ioe) { System.out.println(SCOBUILDER_FAILED); ioe.printStackTrace(); return PROCESSING_COMPLETE; } ctx.put(Keys.XML_SOURCE, manifest); System.out.println("SCOBuilder processing was successful"); } else { System.out.println(SCOBUILDER_FAILED); System.out.println("One of the required Context entries for the " + this.getClass().getSimpleName() + " command to be executed was null"); return PROCESSING_COMPLETE; } return CONTINUE_PROCESSING; }
From source file:dk.netarkivet.archive.checksum.DatabaseChecksumArchive.java
/** * Method for appending a 'wrong' entry in the wrongEntryFile. It will be noted which time the wrong entry was * appended: date + " : " + wrongRecord. * * @param wrongRecord The record to append. * @throws IOFailure If the wrong record cannot be appended correctly. */// www. j a v a 2 s .c om private synchronized void appendWrongRecordToWrongEntryFile(String wrongRecord) throws IOFailure { try { // Create the string to append: date + 'wrong record'. String entry = new Date().toString() + " : " + wrongRecord + "\n"; // get a filewriter for the checksum file, and append the record. boolean appendToFile = true; FileWriter fwrite = new FileWriter(wrongEntryFile, appendToFile); fwrite.append(entry); // close fileWriter. fwrite.flush(); fwrite.close(); } catch (IOException e) { log.warn("Cannot put a bad record to the 'wrongEntryFile'.", e); throw new IOFailure("Cannot put a bad record to the 'wrongEntryFile'.", e); } }