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.onetomany.bidirectional.HardDriveResourceTest.java

public void testHardDrive1() {
    try {//from w w  w.j av  a  2s  .co  m

        String url = baseURL + "/rest/HardDrive/search;id=*/computer";

        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("HardDrive_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.withjoin.FlightResourceTest.java

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

        String url = baseURL + "/rest/Flight/search;id=*/passangerCollection";

        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("Flight_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.withjoin.PassangerResourceTest.java

public void testPassanger1() {
    try {//w  w w  . j  a  v a2 s . c  om

        String url = baseURL + "/rest/Passanger/search;id=*/flight";

        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("Passanger_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.unidirectional.KeyChainResourceTest.java

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

        String url = baseURL + "/rest/KeyChain/search;id=*/keyCollection";

        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("KeyChain_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.unidirectional.withjoin.ShirtResourceTest.java

public void testShirt1() {
    try {/*from   www.j av a  2  s.  com*/

        String url = baseURL + "/rest/Shirt/search;id=*/buttonCollection";

        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("Shirt_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.onetoone.unidirectional.PersonResourceTest.java

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

        String url = baseURL + "/rest/Person/search;id=*/livesAt";

        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("Person_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.onetoone.unidirectional.withjoin.BagResourceTest.java

public void testBag1() {
    try {//from   w  w  w  .j a va2s.c o  m

        String url = baseURL + "/rest/Bag/search;id=*/handle";

        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("Bag_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.differentpackage.associations.IceCreamResourceTest.java

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

        String url = baseURL + "/rest/IceCream/search;id=*/utensilCollection";

        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("IceCream_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.differentpackage.associations.PieResourceTest.java

public void testPie1() {
    try {//from  w ww.j a  v  a2 s.c om

        String url = baseURL + "/rest/Pie/search;id=*/utensilCollection";

        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("Pie_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.differentpackage.associations.UtensilResourceTest.java

public void testUtensil1() {
    try {/*from   w ww  .  ja v a  2  s.  c om*/

        String url = baseURL + "/rest/Utensil/search;id=*/dessertCollection";

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

}