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:com.yourmediashelf.fedora.cargo.FedoraHome.java

private void copyFESLConfigs() throws InstallationFailedException {
    File feslWebDir = new File(_installDir, "server/config/spring/fesl/web");
    File feslModuleDir = new File(_installDir, "server/config/spring/fesl/module");
    File webDir = new File(_installDir, "server/config/spring/web");
    File moduleDir = new File(_installDir, "server/config/spring");

    for (File beanDef : feslWebDir.listFiles()) {
        if (beanDef.isFile()) {
            FileReader reader = null;
            FileWriter writer = null;
            try {
                File copy = new File(webDir, beanDef.getName());
                reader = new FileReader(beanDef);
                writer = new FileWriter(copy);
                IOUtils.copy(reader, writer);
                writer.flush();
            } catch (Exception e) {
                throw new InstallationFailedException(e.getMessage(), e);
            } finally {
                IOUtils.closeQuietly(writer);
                IOUtils.closeQuietly(reader);
            }//from  w  ww  . ja  v a 2 s. c  o m
        }
    }
    for (File beanDef : feslModuleDir.listFiles()) {
        if (beanDef.isFile()) {
            FileReader reader = null;
            FileWriter writer = null;
            try {
                File copy = new File(moduleDir, beanDef.getName());
                reader = new FileReader(beanDef);
                writer = new FileWriter(copy);
                IOUtils.copy(reader, writer);
                writer.flush();
            } catch (Exception e) {
                throw new InstallationFailedException(e.getMessage(), e);
            } finally {
                IOUtils.closeQuietly(writer);
                IOUtils.closeQuietly(reader);
            }
        }
    }
}

From source file:jp.tricreo.codegenerator.service.impl.CodeGenStrategyForVelocity.java

@Override
public void generate(CodeGenContext context) throws CodeGenException {
    Validate.notNull(context);// w w w .ja  va 2s.co m
    File templateDirFile = context.getTemplateDir();
    Properties properties = new Properties();
    properties.setProperty("file.resource.loader.path", templateDirFile.getPath());
    try {
        Velocity.init(properties);
        Template template = Velocity.getTemplate(TEMPLATE_FILENAME, TEMPLATE_FILE_ENCODING);
        DisplayTool displayTool = new DisplayTool();
        for (ClassMetaModel classMetaModel : context.getClassMetaModels()) {
            FileWriter fw = null;
            try {
                VelocityContext velocityContext = new VelocityContext();
                velocityContext.put("displayTool", displayTool);
                velocityContext.put("classMetaModel", classMetaModel);

                File exportClassDir = getExportClassDir(context, classMetaModel);
                exportClassDir.mkdirs();

                fw = new FileWriter(
                        new File(exportClassDir, classMetaModel.getClassName() + "." + GENERATE_FILE_EXT));
                template.merge(velocityContext, fw);
                fw.flush();
                LOGGER.info("????? : {}", classMetaModel.getClassName());
            } catch (Exception e) {
                throw new CodeGenException(e);
            } finally {
                IOUtils.closeQuietly(fw);
            }
        }
    } catch (Exception ex) {
        throw new CodeGenException(ex);
    }
}

From source file:edu.clemson.lph.utils.CSVParserWrapper.java

private static void stripNewLines(File fIn, File fOut) {
    FileReader rIn = null;/*from   w  w  w  .  j a  va2s  .  c  o m*/
    FileWriter wOut = null;
    try {
        rIn = new FileReader(fIn);
        wOut = new FileWriter(fOut);
        int iQuoteCount = 0;
        char cLast = '\0';
        char cThis = '\0';
        int iThis = rIn.read();
        while (iThis >= 0) {
            cThis = (char) iThis;
            if (cThis == '\"') {
                iQuoteCount++;
            }
            if (cThis == '\n' || cThis == '\r') {
                if ((iQuoteCount % 2) > 0) {
                    //               System.err.println("Removed new line after " + iQuoteCount + " quotes");
                    //               new Exception("Removed new line after " + iQuoteCount + " quotes").printStackTrace();
                    //               System.exit(1);
                    cThis = ' ';
                } else {
                    iQuoteCount = 0;
                }
            }
            wOut.append(cThis);
            cLast = cThis;
            iThis = rIn.read();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        logger.error(e);
    } finally {
        try {
            if (rIn != null)
                rIn.close();
            if (wOut != null) {
                wOut.flush();
                wOut.close();
            }
        } catch (IOException e) {
            logger.error(e);
        }
    }
}

From source file:test.gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.PrivateTeacherResourceTest.java

public void testSearch() throws Exception {

    try {/*from ww w.  j  ava  2 s.c  om*/

        String url = baseURL + "/rest/PrivateTeacher/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("PrivateTeacher_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.operations.ChildTestResourceTest.java

public void testSearch() throws Exception {

    try {//  w w w .  j ava  2 s .  c o  m

        String url = baseURL + "/rest/ChildTest/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("ChildTest_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.operations.SiteResourceTest.java

public void testSearch() throws Exception {

    try {//w w w. j a  va2s. c om

        String url = baseURL + "/rest/Site/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("Site_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.operations.SpecimenResourceTest.java

public void testSearch() throws Exception {

    try {//w  ww .j a va2s  . com

        String url = baseURL + "/rest/Specimen/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("Specimen_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.inheritance.childwithassociation.CreditResourceTest.java

public void testSearch() throws Exception {

    try {/* w  ww . j a v a2s . c o  m*/

        String url = baseURL + "/rest/Credit/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("Credit_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.inheritance.implicit.AngelFishResourceTest.java

public void testSearch() throws Exception {

    try {/*  ww w.  j a v a  2  s.  c o  m*/

        String url = baseURL + "/rest/AngelFish/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("AngelFish_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.inheritance.implicit.DiscusFishResourceTest.java

public void testSearch() throws Exception {

    try {/*from ww  w.j  ava 2s .c om*/

        String url = baseURL + "/rest/DiscusFish/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("DiscusFish_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();
    }

}