List of usage examples for java.io FileWriter flush
public void flush() throws IOException
From source file:test.gov.nih.nci.cacoresdk.domain.other.levelassociation.CardResourceTest.java
public void testCard2() { try {/* w ww . jav a 2 s.co m*/ String url = baseURL + "/rest/Card/search;id=*/suit"; 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("Card_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.other.levelassociation.DeckResourceTest.java
public void testDeck1() { try {//w ww . j a va 2 s . c om String url = baseURL + "/rest/Deck/search;id=*/suitCollection"; 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("Deck_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.other.levelassociation.HandResourceTest.java
public void testHand1() { try {/*from w ww .jav a2 s . c om*/ String url = baseURL + "/rest/Hand/search;id=*/cardCollection"; 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("Hand_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:com.searchbox.collection.oppfin.TopicCollection.java
/** * Load HTML page and extract the part with the description * * @param callFileName The call identifier in the URL * @return The html markup that corresponds to the description *//*from w w w.j a va 2 s. co m*/ private String getCallDescription(String callFileName) { // If the call is not cached, load it from URL if (!callList.containsKey(callFileName)) { callList.put(callFileName, new FieldMap()); // callList.put(item.get("callIdentifier").toString(), item); } if (!callList.get(callFileName).containsKey("callDescriptionHtml")) { LOGGER.info("Loading call description [" + callFileName + "]"); String topicUrlDetail = String.format(env.getProperty(CALL_DETAIL_URL, CALL_DETAIL_URL_DEFAULT), callFileName); // String htmlValue = StringUtils.substringBetween( // this.loadFromUrl(topicUrlDetail), // env.getProperty(CALL_DETAIL_BEGIN, CALL_DETAIL_BEGIN_DEFAULT), // env.getProperty(CALL_DETAIL_END, CALL_DETAIL_END_DEFAULT)).trim(); //TODO fix bug LOGGER.info("Loading topic loadFromUrl [" + topicUrlDetail + "]"); String htmlValue = StringUtils.substringBetween(this.loadFromUrl(topicUrlDetail), env.getProperty(CALL_DETAIL_BEGIN, CALL_DETAIL_BEGIN_DEFAULT), env.getProperty(CALL_DETAIL_END, CALL_DETAIL_END_DEFAULT)); if (htmlValue != null) { htmlValue = htmlValue.trim(); } else { htmlValue = "cannot get Description"; } callList.get(callFileName).put("callDescriptionHtml", htmlValue); String callDetailRaw = new HtmlToPlainText().getPlainText(Jsoup.parse(htmlValue)); callList.get(callFileName).put("callDescriptionRaw", callDetailRaw); // Creating a new enhancedCall JSONObject enhancedCall = new JSONObject(); // Pulling full HTML description from the web String callIdentifier = (String) callList.get(callFileName).get("callId").get(0); enhancedCall.put("eur_call_description_html", htmlValue); enhancedCall.put("eur_call_description_raw", callDetailRaw); enhancedCall.put("FileName", callFileName); enhancedCall.put("eur_call_timestamp", Calendar.getInstance().getTime()); enhancedCall.put("eur_call_FileName", callFileName); enhancedCall.put("eur_call_CallId", callIdentifier); // Saving the enhanced file try { File file = new File("output/calls/" + callFileName + ".json"); file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); writer.write(enhancedCall.toJSONString()); writer.flush(); writer.close(); LOGGER.debug("File saved under " + file.getAbsolutePath()); // Saving the list of calls identifiers File file2 = new File("output/calls/calls_identifiers.txt"); FileWriter writer2 = new FileWriter(file2, true); writer2.write(callIdentifier + "\n"); writer2.flush(); writer2.close(); } catch (IOException e) { LOGGER.error(e.getLocalizedMessage()); } } return callList.get(callFileName).get("callDescriptionHtml").toString(); }
From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.sametable.DesignerShoesResourceTest.java
public void testDesignerShoes1() { try {/* w w w.ja v a 2s. c om*/ String url = baseURL + "/rest/DesignerShoes/search;id=*/designer"; 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("DesignerShoes_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.AssistantProfessorResourceTest.java
public void testAssistantProfessor1() { try {/* w ww . j ava 2s .co m*/ String url = baseURL + "/rest/AssistantProfessor/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("AssistantProfessor_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.AssociateProfessorResourceTest.java
public void testAssociateProfessor1() { try {// w ww . j a va 2 s . c o m String url = baseURL + "/rest/AssociateProfessor/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("AssociateProfessor_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.sametable.HardTopResourceTest.java
public void testHardTop1() { try {//from www . j a v a2 s. c o m String url = baseURL + "/rest/HardTop/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("HardTop_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.sametable.HardTopTypeResourceTest.java
public void testHardTopType1() { try {//from ww w. j av a2 s .com String url = baseURL + "/rest/HardTopType/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("HardTopType_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.sametable.LuggageResourceTest.java
public void testLuggage1() { try {//from w w w . j a v a 2s . co m String url = baseURL + "/rest/Luggage/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("Luggage_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()); } }