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:com.yahoo.storm.yarn.TestConfig.java

@SuppressWarnings("rawtypes")
synchronized File createConfigFile(Map storm_conf) throws IOException {
    storm_conf_file = new File("./conf/storm.yaml");
    storm_conf_file.getParentFile().mkdirs();
    Yaml yaml = new Yaml();
    FileWriter writer = new FileWriter(storm_conf_file);
    Util.rmNulls(storm_conf);//  w  w w  . j av a2 s . c om
    yaml.dump(storm_conf, writer);
    writer.flush();
    writer.close();
    return storm_conf_file;
}

From source file:net.itransformers.idiscover.v2.core.listeners.network.NetworkGraphmlFileLogDiscoveryListener.java

@Override
public void networkDiscovered(NetworkDiscoveryResult result) {
    File baseDir = new File(projectPath);
    if (!baseDir.exists())
        baseDir.mkdir();//from  www. j av a 2 s .c  o  m

    File labelDirPath = new File(baseDir, labelDirName);
    if (!labelDirPath.exists())
        labelDirPath.mkdir();

    File graphmlDir = new File(labelDirPath, graphmlDirName);
    if (!graphmlDir.exists())
        graphmlDir.mkdir();

    Map<String, NodeDiscoveryResult> discoveryResultMap = result.getDiscoveredData();
    for (String node : discoveryResultMap.keySet()) {

        byte[] discoveredDeviceData = (byte[]) discoveryResultMap.get(node).getDiscoveredData("graphml");

        try {
            final String fileName = ProjectConstants.networkGraphmlFileName;
            final File nodeFile = new File(graphmlDir, fileName);
            String graphml = new String(discoveredDeviceData);
            FileUtils.writeStringToFile(nodeFile, graphml);
            FileWriter writer = new FileWriter(new File(labelDirPath, "undirected" + ".graphmls"), true);
            writer.append(String.valueOf(fileName)).append("\n");
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

From source file:cc.pinel.mangue.storage.AbstractStorage.java

/**
 * Writes the JSON object to the storage.
 * /*from w ww.  j a  v  a 2 s . c  om*/
 * @param json the JSON object
 * @throws IOException
 */
protected void writeJSON(JSONObject json) throws IOException {
    FileWriter fw = null;

    try {
        fw = new FileWriter(getPath());

        json.writeJSONString(fw);
    } finally {
        if (fw != null)
            fw.close();
    }
}

From source file:com.liferay.ide.project.core.upgrade.UpgradeMetadataHandler.java

private void updateProperties(IFile file, String propertyName, String propertiesValue) throws Exception {
    File osfile = new File(file.getLocation().toOSString());
    PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
    pluginPackageProperties.load(osfile);
    pluginPackageProperties.setProperty(propertyName, propertiesValue);

    FileWriter output = new FileWriter(osfile);

    try {/* ww w  . j av a 2 s .  co  m*/
        pluginPackageProperties.save(output);
    } finally {
        output.close();
    }

    file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
}

From source file:com.jgui.ttscrape.IgnoreListFilter.java

/**
 * Sort then write the file to disk./*  www . j  a va2s . c  om*/
 */
private void writeIgnoreFile() {
    try {
        Collections.sort(titlesToIgnore);
        FileWriter writer = new FileWriter(ignoreFile);
        IOUtils.writeLines(fileHeader, null, writer);
        IOUtils.writeLines(titlesToIgnore, null, writer);
        writer.close();
    } catch (Exception ex) {
        logger.error("failed to write ignore file", ex);
    }
}

From source file:com.michaelfitzmaurice.devtools.HeaderTool.java

/**
 * Inserts the header at the beginning of each file.
 * Does not check whether or not the header is already
 * present./*  w ww.  j ava2s .  c om*/
 * 
 * @param files The files to be amended
 * @throws IOException If something goes wrong reading 
 *          from or writing to any of the files
 */
public void insertHeader(Collection<File> files) throws IOException {

    LOG.info("Inserting header from {} into {} files", headerFile, files.size());

    for (File file : files) {
        String originalFileContent = fileContents(file);
        FileWriter writer = new FileWriter(file);
        writer.write(header);
        writer.write(originalFileContent);
        writer.close();
        LOG.info("Added header to {}", file);
    }
}

From source file:com.bc.fiduceo.post.PostProcessingTool_IOTest.java

@Test
public void testInitialisation() throws Exception {
    final Options options = PostProcessingTool.getOptions();
    final PosixParser parser = new PosixParser();
    final CommandLine commandLine = parser.parse(options, new String[] { "-j", processingConfigName, "-i",
            "/mmd_files", "-start", "2011-123", "-end", "2011-124", "-c", configDir.getPath() });

    final FileWriter fileWriter = new FileWriter(new File(configDir, "system-config.xml"));
    fileWriter.write("<system-config></system-config>");
    fileWriter.close();

    final PostProcessingContext context = PostProcessingTool.initializeContext(commandLine);

    final String separator = FileSystems.getDefault().getSeparator();
    assertEquals(separator + "mmd_files", context.getMmdInputDirectory().toString());
    assertEquals("03-May-2011 00:00:00", ProductData.UTC.createDateFormat().format(context.getStartDate()));
    assertEquals("04-May-2011 23:59:59", ProductData.UTC.createDateFormat().format(context.getEndDate()));

    final SystemConfig sysConfig = context.getSystemConfig();
    assertNotNull(sysConfig);/* w  w  w.  j  av a2  s .c o  m*/
    assertNull(sysConfig.getArchiveConfig());

    final PostProcessingConfig config = context.getProcessingConfig();
    assertNotNull(config);
    final List<Element> postProcessingElements = config.getPostProcessingElements();
    assertNotNull(postProcessingElements);
    assertEquals("java.util.Collections$UnmodifiableList", postProcessingElements.getClass().getTypeName());
    assertEquals(1, postProcessingElements.size());
    assertEquals(TAG_NAME_SPHERICAL_DISTANCE, postProcessingElements.get(0).getName());
}

From source file:net.blogracy.controller.DistributedHashTable.java

public void putRecord(JSONObject record) {
    try {/* w w w .j av a 2 s.c  o m*/
        records.put(record.getString("id"), record);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }
    JSONArray recordList = new JSONArray();
    Iterator<JSONObject> entries = records.values().iterator();
    while (entries.hasNext()) {
        JSONObject entry = entries.next();
        recordList.put(entry);
    }
    File recordsFile = new File(CACHE_FOLDER + File.separator + "records.json");
    try {
        FileWriter writer = new FileWriter(recordsFile);
        recordList.write(writer);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:net.douglasthrift.bigscreenbot.Settings.java

public void store() throws IOException {
    FileWriter writer = null;

    try {/*  w  w w. j a  v  a2  s .co m*/
        writer = new FileWriter(SETTINGS);

        store(writer, null);
    } finally {
        if (writer != null)
            writer.close();
    }
}

From source file:fr.inria.oak.paxquery.algebra.operators.BaseLogicalOperator.java

public void draw(String folder, String givenFileName) {
    //System.out.println("BaseLogicalOperator:");
    //System.out.println("\tfolder: "+folder);
    //System.out.println("\tgivenFileName: "+givenFileName);

    StringBuffer sb = new StringBuffer();
    sb.append("digraph  g{\n edge [dir=\"back\"]\n");
    recursiveDotString(sb, 0, 100);//  w w  w  . j a v a  2s . c  o  m
    try {
        if (givenFileName == null) {
            givenFileName = "" + System.currentTimeMillis();
        }
        String pathName = "";
        int lastSlash = givenFileName.lastIndexOf(File.separator);
        if (lastSlash > 0) {
            pathName = givenFileName.substring(0, lastSlash);
            File dir = new File(pathName);
            dir.mkdirs();
        }

        String fileNameDot = new String(folder + File.separator + givenFileName + "-logplan.dot");
        String fileNamePNG = new String(folder + File.separator + givenFileName + "-logplan.png");

        //System.out.println("fileNameDot: "+fileNameDot);
        FileWriter file = new FileWriter(fileNameDot);
        file.write(new String(sb));
        file.write("}\n");
        file.close();
        Runtime r = Runtime.getRuntime();
        String com = new String("dot -Tpng " + fileNameDot + " -o " + fileNamePNG);
        Process p = r.exec(com);
        p.waitFor();
        //System.out.println("Logical plan drawn.");
        logger.debug("Logical plan drawn.");
    } catch (Exception e) {
        logger.error("Exception: ", e);
    }
}