List of usage examples for java.io FileWriter flush
public void flush() throws IOException
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.parentwithassociation.sametable.SoftTopResourceTest.java
public void testSoftTop1() { try {/*from w w w.j a va 2s .c o m*/ String url = baseURL + "/rest/SoftTop/search;id=*/wheel"; 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("SoftTop_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(); ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR); builder.type("application/xml"); StringBuffer buffer = new StringBuffer(); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<response>"); buffer.append("<type>ERROR</type>"); buffer.append("<code>INTERNAL_ERROR_4</code>"); buffer.append("<message>Failed to Query due to: " + e.getMessage() + "</message>"); buffer.append("</response>"); builder.entity(buffer.toString()); throw new WebApplicationException(builder.build()); } }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.parentwithassociation.TenuredProfessorResourceTest.java
public void testTenuredProfessor1() { try {//from w w w.j ava2 s. c om String url = baseURL + "/rest/TenuredProfessor/search;id=*/assistantCollection"; 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("TenuredProfessor_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(); ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR); builder.type("application/xml"); StringBuffer buffer = new StringBuffer(); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<response>"); buffer.append("<type>ERROR</type>"); buffer.append("<code>INTERNAL_ERROR_4</code>"); buffer.append("<message>Failed to Query due to: " + e.getMessage() + "</message>"); buffer.append("</response>"); builder.entity(buffer.toString()); throw new WebApplicationException(builder.build()); } }
From source file:de.qaware.chronix.importer.csv.FileImporter.java
private void writeStatsLine(FileWriter metricsFile, Attributes attributes, Instant start, Instant end) throws IOException { //host:process:metric-group:metric:start:end StringBuilder line = new StringBuilder(); for (int i = 0; i < attributes.size(); i++) { line.append(attributes.get(i)).append(csvDelimiter); }//from w ww .j a v a2s . c om line.append(start).append(csvDelimiter).append(end).append(csvDelimiter).append("\n"); metricsFile.write(line.toString()); metricsFile.flush(); }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.PrivateTeacherResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set// ww w . ja v a 2 s . c o m * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { PrivateTeacher searchObject = new PrivateTeacher(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.PrivateTeacher", searchObject); String id = ""; if (results != null && results.size() > 0) { PrivateTeacher obj = (PrivateTeacher) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/PrivateTeacher/" + 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("PrivateTeacher" + "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(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.CreditResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/*from w w w.j a va 2 s . co m*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { Credit searchObject = new Credit(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Credit", searchObject); String id = ""; if (results != null && results.size() > 0) { Credit obj = (Credit) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/Credit/" + 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("Credit" + "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(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.implicit.AngelFishResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/* w ww . j av a 2 s . c o m*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { AngelFish searchObject = new AngelFish(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.inheritance.implicit.AngelFish", searchObject); String id = ""; if (results != null && results.size() > 0) { AngelFish obj = (AngelFish) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/AngelFish/" + 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("AngelFish" + "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(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.implicit.DiscusFishResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/*ww w . j a va 2s . c om*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { DiscusFish searchObject = new DiscusFish(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.inheritance.implicit.DiscusFish", searchObject); String id = ""; if (results != null && results.size() > 0) { DiscusFish obj = (DiscusFish) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/DiscusFish/" + 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("DiscusFish" + "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(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.implicit.FishResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/*from w w w . java 2 s .c o m*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { Fish searchObject = new Fish(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.inheritance.implicit.Fish", searchObject); String id = ""; if (results != null && results.size() > 0) { Fish obj = (Fish) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/Fish/" + 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("Fish" + "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(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.implicit.SaltwaterFishTankResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/* www. j a va 2s. c o m*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { SaltwaterFishTank searchObject = new SaltwaterFishTank(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.inheritance.implicit.SaltwaterFishTank", searchObject); String id = ""; if (results != null && results.size() > 0) { SaltwaterFishTank obj = (SaltwaterFishTank) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/SaltwaterFishTank/" + 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("SaltwaterFishTank" + "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(); throw e; } }