Example usage for java.io FileWriter close

List of usage examples for java.io FileWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:mn.EngineForge.module.player.java

public void saveRegisteration() throws IOException {
    JSONObject reg = new JSONObject();
    reg.put("ID", id);
    reg.put("USERNAME", username);
    reg.put("PASSWORD", password);
    reg.put("REG_DATE", null);
    reg.put("LAST_LOGIN", null);
    reg.put("POSITION", null);
    /* JSON ARRAY NOTE/*from   w  ww.  j  a v  a2s. co  m*/
    JSONArray company = new JSONArray();
    company.add("Compnay: eBay");
    company.add("Compnay: Paypal");
    company.add("Compnay: Google");
    reg.put("Company List", company);
    */
    FileWriter file = new FileWriter(this.path);
    try {
        file.write(reg.toJSONString());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        file.flush();
        file.close();
    }
}

From source file:com.granita.contacticloudsync.ui.DebugInfoActivity.java

public void onShare(MenuItem item) {
    if (!TextUtils.isEmpty(report)) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Exception Details");

        try {//from w  w w  .  j  a  va2  s .  c  om
            File reportFile = File.createTempFile("debug", ".txt", getExternalCacheDir());
            Constants.log.debug("Writing debug info to " + reportFile.getAbsolutePath());
            FileWriter writer = new FileWriter(reportFile);
            writer.write(report);
            writer.close();

            sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(reportFile));
        } catch (IOException e) {
            // let's hope the report is < 1 MB
            sendIntent.putExtra(Intent.EXTRA_TEXT, report);
        }

        startActivity(sendIntent);
    }
}

From source file:accismus.benchmark.BenchTestIT.java

private void verifyMR() throws Exception {

    // TODO use junit tmp file
    String propsFile = FileUtils.getTempDirectoryPath() + File.separator + "ab_verify"
            + UUID.randomUUID().toString() + ".props";
    String outputDir = FileUtils.getTempDirectoryPath() + File.separator + "ab_verify"
            + UUID.randomUUID().toString();

    FileWriter fw = new FileWriter(propsFile);
    connectionProps.store(fw, "");
    fw.close();

    Verifier.main(new String[] { "-D", "mapred.job.tracker=local", "-D", "fs.default.name=file:///", propsFile,
            outputDir });//from  w  w  w .  j a v  a2  s  . c  o  m
}

From source file:org.mashupmedia.service.MapperManagerImpl.java

@Override
public void writeSongToXml(long libraryId, Song song) throws Exception {
    if (song == null) {
        return;/*from w w w.  j  av  a 2 s .c  om*/
    }

    Song clonedSong = SerializationUtils.clone(song);
    clonedSong.setId(0);
    clonedSong.setPath(String.valueOf(song.getId()));

    String fileName = clonedSong.getFileName();
    clonedSong.setFileName(StringHelper.escapeXml(fileName));

    String songTitle = clonedSong.getTitle();
    clonedSong.setTitle(StringHelper.escapeXml(songTitle));

    String songSearchText = clonedSong.getSearchText();
    clonedSong.setSearchText(StringHelper.escapeXml(songSearchText));

    String summary = clonedSong.getSummary();
    clonedSong.setSummary(StringHelper.escapeXml(summary));

    String displayTitle = clonedSong.getDisplayTitle();
    clonedSong.setDisplayTitle(StringHelper.escapeXml(displayTitle));

    Artist clonedArtist = SerializationUtils.clone(song.getArtist());
    String artistName = clonedArtist.getName();
    clonedArtist.setName(StringHelper.escapeXml(artistName));
    String artistIndexText = clonedArtist.getIndexText();
    clonedArtist.setIndexText(StringHelper.escapeXml(artistIndexText));
    clonedSong.setArtist(clonedArtist);

    Album clonedAlbum = SerializationUtils.clone(song.getAlbum());
    String albumName = clonedAlbum.getName();
    clonedAlbum.setName(StringHelper.escapeXml(albumName));
    String albumFolderName = clonedAlbum.getFolderName();
    clonedAlbum.setFolderName(StringHelper.escapeXml(albumFolderName));
    clonedSong.setAlbum(clonedAlbum);

    File file = FileHelper.getLibraryXmlFile(libraryId);

    FileWriter writer = new FileWriter(file, true);
    getMarshaller().marshal(clonedSong, new StreamResult(writer));
    writer.close();
}

From source file:cz.msebera.unbound.dns.fragments.MainLogFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_EMPTY:
        try {/*from  www .  j  a  v a  2s.c o m*/
            FileWriter fw = new FileWriter(
                    new File(getActivity().getFilesDir(), getString(R.string.path_mainlog)), false);
            fw.write("");
            fw.close();
            Toast.makeText(getActivity(), R.string.configuration_saved, Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            Log.e(TAG, getString(R.string.error_cannot_write_unbound_conf), e);
        }
    case MENU_CLEAR:
        mTextArea.setText("");
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.mellanox.r4h.MiniDFSClusterManager.java

/**
 * Starts DFS as specified in member-variable options. Also writes out
 * configuration and details, if requested.
 *///from   w ww  .  j av a2 s.  c  o  m
public void start() throws IOException, FileNotFoundException {
    dfs = new MiniDFSCluster.Builder(conf).nameNodePort(nameNodePort).numDataNodes(numDataNodes)
            .startupOption(dfsOpts).format(format).build();
    dfs.waitActive();

    LOG.info("Started MiniDFSCluster -- namenode on port " + dfs.getNameNodePort());

    if (writeConfig != null) {
        FileOutputStream fos = new FileOutputStream(new File(writeConfig));
        conf.writeXml(fos);
        fos.close();
    }

    if (writeDetails != null) {
        Map<String, Object> map = new TreeMap<String, Object>();
        if (dfs != null) {
            map.put("namenode_port", dfs.getNameNodePort());
        }

        FileWriter fw = new FileWriter(new File(writeDetails));
        fw.write(new JSON().toJSON(map));
        fw.close();
    }
}

From source file:WebCategorizer.java

private JSONObject fetchCategories() {
    try {//  w w w. ja v  a2s .  com
        JSONObject webCatList = new JSONObject();
        URL obj = new URL(categoriesUrl);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        con.setRequestProperty("User-agent", "Web Categorizer");
        int responseCode = con.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            JSONArray inputData = new JSONArray(response.toString());
            for (Object currObj : inputData) {
                JSONObject tempObj = (JSONObject) currObj;
                webCatList.put(String.format("%02X", tempObj.get("num")).toLowerCase(), tempObj.get("name"));
            }

            FileWriter file = new FileWriter(categoriesFile);
            file.write(webCatList.toString());
            file.flush();
            file.close();
        } else {
            System.out.println("Not working");
        }
        return webCatList;
    } catch (Exception ex) {
        return new JSONObject();
    }
}

From source file:org.jenkins.tools.test.model.MavenPom.java

public void addDependencies(Map<String, VersionNumber> toAdd, Map<String, VersionNumber> toReplace,
        VersionNumber coreDep, Map<String, String> pluginGroupIds) throws IOException {
    File pom = new File(rootDir.getAbsolutePath() + "/" + pomFileName);
    Document doc;/*from  www.  ja  v a2  s. co  m*/
    try {
        doc = new SAXReader().read(pom);
    } catch (DocumentException x) {
        throw new IOException(x);
    }
    Element dependencies = doc.getRootElement().element("dependencies");
    if (dependencies == null) {
        dependencies = doc.getRootElement().addElement("dependencies");
    }
    for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) {
        Element artifactId = mavenDependency.element("artifactId");
        if (artifactId == null || !"maven-plugin".equals(artifactId.getTextTrim())) {
            continue;
        }
        Element version = mavenDependency.element("version");
        if (version == null || version.getTextTrim().startsWith("${")) {
            // Prior to 1.532, plugins sometimes assumed they could pick up the Maven plugin version from their parent POM.
            if (version != null) {
                mavenDependency.remove(version);
            }
            version = mavenDependency.addElement("version");
            version.addText(coreDep.toString());
        }
    }
    for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) {
        Element artifactId = mavenDependency.element("artifactId");
        if (artifactId == null) {
            continue;
        }
        excludeSecurity144Compat(mavenDependency);
        VersionNumber replacement = toReplace.get(artifactId.getTextTrim());
        if (replacement == null) {
            continue;
        }
        Element version = mavenDependency.element("version");
        if (version != null) {
            mavenDependency.remove(version);
        }
        version = mavenDependency.addElement("version");
        version.addText(replacement.toString());
    }
    dependencies.addComment("SYNTHETIC");
    for (Map.Entry<String, VersionNumber> dep : toAdd.entrySet()) {
        Element dependency = dependencies.addElement("dependency");
        String group = pluginGroupIds.get(dep.getKey());

        // Handle cases where plugin isn't under default groupId
        if (group != null && !group.isEmpty()) {
            dependency.addElement("groupId").addText(group);
        } else {
            dependency.addElement("groupId").addText("org.jenkins-ci.plugins");
        }
        dependency.addElement("artifactId").addText(dep.getKey());
        dependency.addElement("version").addText(dep.getValue().toString());
        excludeSecurity144Compat(dependency);
    }
    FileWriter w = new FileWriter(pom);
    try {
        doc.write(w);
    } finally {
        w.close();
    }
}

From source file:com.att.aro.core.settings.impl.JvmSettings.java

@Override
public void saveConfigFile() {
    try {/* www .  j av  a2s  .  co m*/
        FileWriter writer = new FileWriter(CONFIG_FILE_PATH);
        LOGGER.debug("Persisting properties to: " + CONFIG_FILE_PATH);
        writer.close();
    } catch (IOException e) {
        throw new ARORuntimeException("Could not save vm options file: " + e.getLocalizedMessage(), e);
    }
}

From source file:presenter.MainPresenter.java

@Override
public void saveMovementsequenceToFile(ActionEvent e) {
    JFileChooser fc = new JFileChooser();

    if (fc.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {//from   w  w  w.  ja  v a  2s .  c om
            FileWriter fw = new FileWriter(file);
            fw.write(this.movSeq.toString());
            fw.flush();
            fw.close();
            this.displayStatus("File was written successfully!");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}