Example usage for java.io FileWriter flush

List of usage examples for java.io FileWriter flush

Introduction

In this page you can find the example usage for java.io FileWriter flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.implicit.SaltwaterFishTankResourceTest.java

public void testSaltwaterFishTank1() {
    try {/*  www . ja  v  a2s . c om*/

        String url = baseURL + "/rest/SaltwaterFishTank/search;id=*/substrateCollection";

        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_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.implicit.TankAccessoryResourceTest.java

public void testTankAccessory1() {
    try {/*from   w w w  . j a  va  2  s .  c  o m*/

        String url = baseURL + "/rest/TankAccessory/search;id=*/tankCollection";

        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("TankAccessory_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.ProfessorResourceTest.java

public void testProfessor1() {
    try {//from w  ww.ja  v  a  2 s . co  m

        String url = baseURL + "/rest/Professor/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("Professor_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.WheelResourceTest.java

public void testWheel1() {
    try {/*  w  ww  . j a va  2  s  .c  om*/

        String url = baseURL + "/rest/Wheel/search;id=*/luggage";

        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("Wheel_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.manytomany.bidirectional.EmployeeResourceTest.java

public void testEmployee1() {
    try {/*  ww  w.j a v a2  s  . co m*/

        String url = baseURL + "/rest/Employee/search;id=*/projectCollection";

        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("Employee_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.manytomany.bidirectional.ProjectResourceTest.java

public void testProject1() {
    try {/*from  ww w . j  ava2s .  c  o  m*/

        String url = baseURL + "/rest/Project/search;id=*/employeeCollection";

        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("Project_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.manytomany.unidirectional.BookResourceTest.java

public void testBook1() {
    try {/*from www.  j av a  2 s . co  m*/

        String url = baseURL + "/rest/Book/search;id=*/authorCollection";

        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("Book_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.manytoone.unidirectional.ChefResourceTest.java

public void testChef1() {
    try {//from   w  ww  .  j ava2s  .  c  om

        String url = baseURL + "/rest/Chef/search;id=*/restaurant";

        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("Chef_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.manytoone.unidirectional.withjoin.SongResourceTest.java

public void testSong1() {
    try {//from w ww.ja v  a 2s.c o  m

        String url = baseURL + "/rest/Song/search;id=*/album";

        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("Song_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.onetomany.bidirectional.ComputerResourceTest.java

public void testComputer1() {
    try {/*from   w  w  w .  j a  v a2  s . com*/

        String url = baseURL + "/rest/Computer/search;id=*/hardDriveCollection";

        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("Computer_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());
    }

}