Example usage for java.io BufferedWriter close

List of usage examples for java.io BufferedWriter close

Introduction

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

Prototype

@SuppressWarnings("try")
    public void close() throws IOException 

Source Link

Usage

From source file:me.m0r13.maptools.MarkerUpdateTask.java

public void writePlayers(Player[] players) {
    JSONArray playersJson = new JSONArray();
    for (Player player : players) {
        JSONObject json = new JSONObject();

        Location pos = player.getLocation();
        World world = player.getWorld();

        json.put("username", player.getName());
        json.put("x", pos.getX());
        json.put("y", pos.getY());
        json.put("z", pos.getZ());
        json.put("world", world.getName());
        json.put("dimension", world.getEnvironment().toString());
        json.put("health", player.getHealth());
        json.put("saturation", player.getSaturation());
        json.put("food", player.getFoodLevel());
        Location bed = player.getBedSpawnLocation();
        if (bed == null) {
            json.put("bed", null);
        } else {//ww w.jav a 2 s.  c o  m
            JSONArray bedJson = new JSONArray();
            bedJson.add(bed.getBlockX());
            bedJson.add(bed.getBlockY());
            bedJson.add(bed.getBlockZ());
            json.put("bed", bedJson);
        }
        json.put("level", (float) player.getLevel() + player.getExp());
        playersJson.add(json);
    }
    JSONObject json = new JSONObject();
    json.put("players", playersJson);

    try {
        File file = new File(plugin.getConfig().getString("markerFile"));
        BufferedWriter output = new BufferedWriter(new FileWriter(file));
        output.write(json.toJSONString());
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.cyberway.issue.crawler.frontier.AbstractFrontier.java

/**
 * Dump ignored seed items (if any) to disk; delete file otherwise.
 * Static to allow non-derived sibling classes (frontiers not yet 
 * subclassed here) to reuse./*w  w w . j  av  a  2  s . c  o  m*/
 * 
 * @param ignoredItems
 * @param dir 
 */
public static void saveIgnoredItems(String ignoredItems, File dir) {
    File ignoredFile = new File(dir, IGNORED_SEEDS_FILENAME);
    if (ignoredItems == null | ignoredItems.length() > 0) {
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(ignoredFile));
            bw.write(ignoredItems);
            bw.close();
        } catch (IOException e) {
            // TODO make an alert?
            e.printStackTrace();
        }
    } else {
        // delete any older file (if any)
        ignoredFile.delete();
    }
}

From source file:com.stefanbrenner.droplet.ui.actions.SaveFileAction.java

protected void saveFile(final File file) {
    try {/*from www . ja  v a  2 s.co  m*/

        IDroplet droplet = getDropletContext().getDroplet();

        JAXBHelper jaxbHelper = new JAXBHelper();
        String xml = jaxbHelper.toXml(droplet);

        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write(xml);
        out.close();

    } catch (IOException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

From source file:com.microsoft.alm.plugin.idea.common.setup.ApplicationStartupTest.java

public void writeToFile(File file, String content) throws Exception {
    FileWriter fileWriter = new FileWriter(file.getPath());
    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    bufferedWriter.write(content);/*from w  w w  . ja va2 s .  c  o m*/
    bufferedWriter.close();
}

From source file:com.photon.phresco.util.ProjectUtils.java

/**
 * To update the project.info file with the new info
 * @param projectInfo/*from www. j  a  va  2 s  .co m*/
 * @param projectInfoFile
 * @throws PhrescoException
 */
public static void updateProjectInfo(ProjectInfo projectInfo, File projectInfoFile) throws PhrescoException {
    BufferedWriter out = null;
    FileWriter fstream = null;
    try {
        Gson gson = new Gson();
        String infoJSON = gson.toJson(projectInfo);
        fstream = new FileWriter(projectInfoFile.getPath());
        out = new BufferedWriter(fstream);
        out.write(infoJSON);
    } catch (IOException e) {
        throw new PhrescoException(e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
            if (fstream != null) {
                fstream.close();
            }
        } catch (IOException e) {
            throw new PhrescoException(e);
        }
    }
}

From source file:gemlite.core.internal.batch.BatchGenenator.java

/***
 * create xml file at GS_HOME/batchFile/*from  w  w  w  .  j  a va  2  s .  c o m*/
 * 
 * @param fileName
 * @param content
 * @return
 */
private String writeOneFile(String fileName, String content) {
    try {
        File f = new File(batchFilePath, fileName);
        BufferedWriter bw = new BufferedWriter(new FileWriterWithEncoding(f, "utf-8"));
        bw.write(content);
        bw.close();
        LogUtil.getCoreLog().info("Batch file created at " + f.getAbsolutePath());
        return f.toURI().toString();
    } catch (Exception e) {
        throw new GemliteException(e);
    }
}

From source file:ir.pooyahfp.matrixcli.ProgramTest.java

@Test
public void testLoadCommandFile() throws Exception {
    String path = "test.txt";
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(path)));
    writer.write("matrix x 3 3");
    writer.newLine();/*from ww w.  java  2s.co m*/
    writer.write("show x");
    writer.flush();
    writer.close();

    program.loadCommandFile(path);
}

From source file:com.depas.utils.FileUtils.java

public static void writeArrayToFile(String fileName, String[] contents, boolean utfEncoding)
        throws IOException {
    BufferedWriter out = null;
    try {//from w w  w  .ja va2 s  .c  o m
        File outFile = new File(fileName);
        OutputStreamWriter osw;
        if (utfEncoding) {
            osw = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8");
        } else {
            osw = new OutputStreamWriter(new FileOutputStream(outFile));
        }
        out = new BufferedWriter(osw);
        for (int i = 0; i < contents.length; i++) {
            out.write(contents[i]);
            out.newLine();
        }
        out.close();
        out = null;
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:com.seniorproject.semanticweb.services.HadoopService.java

private void createSparqlFile(String queryString) throws IOException {
    String prefix = "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
            + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
            + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
            + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
            + "PREFIX oddlinker: <http://data.linkedmdb.org/resource/oddlinker/> "
            + "PREFIX map: <file:/C:/d2r-server-0.4/mapping.n3#> "
            + "PREFIX db: <http://data.linkedmdb.org/resource/> "
            + "PREFIX dbpedia: <http://dbpedia.org/property/> "
            + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "PREFIX dc: <http://purl.org/dc/terms/> "
            + "PREFIX movie: <http://data.linkedmdb.org/resource/movie/> ";
    File file = new File(servletContext.getRealPath("/WEB-INF/classes/PigSPARQL_v1.0/"), "test1.sparql");

    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(prefix + queryString);//from  w w w  .  j av a 2s  .c o m
    bw.close();
}

From source file:io.druid.storage.google.GoogleTaskLogsTest.java

@Test
public void testPushTaskLog() throws Exception {
    final File tmpDir = Files.createTempDir();

    try {/*  w  w  w .j  ava 2s .  co  m*/
        final File logFile = new File(tmpDir, "log");
        BufferedWriter output = new BufferedWriter(new FileWriter(logFile));
        output.write("test");
        output.close();

        storage.insert(EasyMock.eq(bucket), EasyMock.eq(prefix + "/" + taskid),
                EasyMock.anyObject(InputStreamContent.class));
        expectLastCall();

        replayAll();

        googleTaskLogs.pushTaskLog(taskid, logFile);

        verifyAll();
    } finally {
        FileUtils.deleteDirectory(tmpDir);
    }
}