Example usage for java.io FileWriter write

List of usage examples for java.io FileWriter write

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:de.indiplex.javapt.JavAPT.java

public void addSource(String source) throws IOException {
    String s = checkURL(source);/*from  w ww  .j av a  2 s  .com*/
    if (s == null) {
        System.out.println(source + " is not a valid Cydia repo!");
    } else {
        FileWriter fw = new FileWriter(fSources, true);
        fw.write(s + "\n");
        fw.close();
        sourcesURLs.add(s);
        System.out.println("Added source " + source);
        if (isGUI()) {
            mf.fillSources(sourcesURLs);
        }
    }
}

From source file:com.mindquarry.desktop.client.dialog.conflict.ContentConflictDialog.java

private void mergeWordDocumentsManually(Status status, String basePath) throws IOException {
    File localVersion = new File(status.getPath());
    File serverVersion = new File(basePath, status.getConflictNew());
    log.debug("merge: serverVersion: " + serverVersion);
    log.debug("merge: localVersion: " + localVersion);

    // use the correct filename suffix:
    String suffix = FilenameUtils.getExtension(localVersion.getName());
    File tmpServerVersion = File.createTempFile("mindquarry-merge-server", "." + suffix);
    FileUtils.copyFile(serverVersion, tmpServerVersion);
    tempFiles.add(tmpServerVersion);/*from  ww w  .j  a v  a2  s. co  m*/

    mergedVersion = File.createTempFile("mindquarry-merge-local", "." + suffix);
    FileUtils.copyFile(localVersion, mergedVersion);
    tempFiles.add(mergedVersion);

    File tmpScriptFile = File.createTempFile("mindquarry-merge-script", ".js");
    tempFiles.add(tmpScriptFile);

    //
    // FIXME: delete temp files also in case of 'cancel'
    //

    // load script from JAR and save as temp file to avoid path problems:
    InputStream is = getClass().getResourceAsStream("/scripts/merge-doc.js");
    String script = loadInputStream(is);
    FileWriter fw = new FileWriter(tmpScriptFile);
    fw.write(script);
    fw.close();
    String mergeScript = tmpScriptFile.getAbsolutePath();

    String[] cmdArray = new String[] { "wscript", mergeScript, mergedVersion.getAbsolutePath(),
            tmpServerVersion.getAbsolutePath() };
    log.debug("Calling merge script: " + Arrays.toString(cmdArray));

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmdArray);
    int exitValue = -1;
    try {
        exitValue = proc.waitFor();
    } catch (InterruptedException e) {
        throw new RuntimeException(e.toString(), e);
    }
    log.debug("Exit value " + exitValue);
    if (exitValue != 0) {
        mergeOptionButton.setEnabled(false);
        mergeButton.setEnabled(false);
        okButton.setEnabled(true); // let user continue with other option
        MessageDialog
                .openError(
                        getShell(), I18N.getString("Error executing MS Word"), I18N
                                .getString("The script used to merge documents "
                                        + "using MS Word could not be started. The exit " + "code was ")
                                + exitValue);
    }
}

From source file:apim.restful.exportimport.APIService.java

/**
 * Retrieve documentation for the exporting API and store it in the archive directory
 * FILE, INLINE and URL documentations are handled
 *
 * @param docList  documentation list of the exporting API
 * @throws APIExportException  If an error occurs while retrieving documents from the
 * registry or storing in the archive directory
 *///from  ww  w  .  j  av a 2 s.  c o m
private void getAPIDocumentation(List<Documentation> docList) throws APIExportException {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    createDirectory(baseAPIArchivePath + "/Docs");

    try {
        for (Documentation doc : docList) {
            String sourceType = doc.getSourceType().name();

            if (sourceType.equalsIgnoreCase(Documentation.DocumentSourceType.FILE.toString())) {
                String fileName = doc.getFilePath().substring(doc.getFilePath().lastIndexOf("/") + 1);
                String filePath = APIUtil.getDocumentationFilePath(apiIdentifier, fileName);

                //check whether resource exists in the registry
                Resource docFile = registry.get(filePath);
                String localFilePath = "/Docs/" + fileName;
                OutputStream os = new FileOutputStream(baseAPIArchivePath + localFilePath);
                InputStream fileInputStream = docFile.getContentStream();
                byte[] b = new byte[2048];
                int length;

                while ((length = fileInputStream.read(b)) != -1) {
                    os.write(b, 0, length);
                }

                fileInputStream.close();
                os.close();
                doc.setFilePath(localFilePath);
            }
        }

        String json = gson.toJson(docList);
        FileWriter writer = new FileWriter(baseAPIArchivePath + "/Docs/docs.json");
        writer.write(json);
        writer.close();

    } catch (IOException e) {
        log.error("I/O error while writing API documentation to file" + e.toString());
        throw new APIExportException("I/O error while writing API documentation to file", e);
    } catch (RegistryException e) {
        log.error("Error while retrieving documentation " + e.toString());
        throw new APIExportException("Error while retrieving documentation", e);
    }
}

From source file:org.ala.spatial.web.services.SitesBySpeciesWSControllerTabulated.java

@RequestMapping(value = { "sxs/delete", "sxs/sxs/delete" }, method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView sxsDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    String url = req.getParameter("u");

    try {/*from w  w  w. ja v a  2 s .c  o m*/
        String pth = AlaspatialProperties.getAnalysisWorkingDir() + File.separator + "sxs" + File.separator;

        initListProperties();
        Properties p = new Properties();
        p.load(new FileReader(pth + "list.properties"));

        for (Entry<Object, Object> entry : p.entrySet()) {
            if (((String) entry.getValue()).equals(url)) {
                FileWriter fw = new FileWriter(pth + ((String) entry.getKey()));
                fw.write("-1");
                fw.flush();
                fw.close();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return new ModelAndView("redirect:" + AlaspatialProperties.getAlaspatialUrl() + "/sxs");
}

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

public void testSearch() throws Exception {

    try {/*from  w  w w. j  av  a 2  s .com*/

        String url = baseURL + "/rest/Pupil/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("Pupil_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.BankResourceTest.java

public void testSearch() throws Exception {

    try {// w w w. ja v a  2s .com

        String url = baseURL + "/rest/Bank/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("Bank_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.CashResourceTest.java

public void testSearch() throws Exception {

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

        String url = baseURL + "/rest/Cash/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("Cash_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.PaymentResourceTest.java

public void testSearch() throws Exception {

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

        String url = baseURL + "/rest/Payment/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("Payment_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.sametable.ShoesResourceTest.java

public void testSearch() throws Exception {

    try {//w  w  w.  ja  va 2 s. c  om

        String url = baseURL + "/rest/Shoes/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("Shoes_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.FishTankResourceTest.java

public void testSearch() throws Exception {

    try {//from   www .  j a  v  a  2 s  . c om

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

}